Jarvis in C# by Salim SR   1 year ago


57 Likes   4 Dislikes

Personal Assistant Demo C# Tutorial is coming soon ...
Here is the code for speech recognition :

//////////////here voice search ////////////////////////////
SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
Grammar dictationGrammar = new DictationGrammar();
RecognitionResult result = recognizer.Recognize();
input.Text = result.Text;
catch (Exception)
computer.Speak("Could not recognize input from default aduio device. Is a microphone or sound card available");

//////////Search Button code ///////////////////

string urlAddress = input.Text;
webBrowser.Navigate("https://www.bing.com/search?q=/" + urlAddress);
/////////end here ///////////////////////////

thats it you done ...
///////////////////////Open file from base directory //////////////////////////////////////////////////////

String Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

Process process = new Process();

process.StartInfo = new ProcessStartInfo()
FileName = Path + "\\Documents\\somePDFfile.pdf"


//////////////////For Shutdown Restart Log Off Commands ////////////////////////
First, add this using namespace statements:

using System.Diagnostics;
using System.Runtime.InteropServices;

To shut down your computer, use this code:

Process.Start("shutdown","/s /t 0");

To restart your computer, use this code:

Process.Start("shutdown","/r /t 0"); // the argument /r is to restart the computer

To add this extern method to your class for (Log off)

public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);

Then, to log off, invoke the method:


To lock your computer, add this extern method to your class:

public static extern void LockWorkStation();

Then, to lock, invoke the method:


To put your computer in Hibernate or Sleep, you need the same DllImport statement for them.

[DllImport("PowrProf.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent);

To bring your computer into Hibernate:

SetSuspendState(true, true, true);

And to bring it into sleep:

SetSuspendState(false, true, true);

///////////////////////////How to write text in notepad using textbox ////////////////////////////////////////////
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Drawing;

using System.Linq;

using System.Runtime.InteropServices;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace MyForm


public partial class Form1 : Form


[DllImport("user32.dll", EntryPoint = "FindWindowEx")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

public Form1()




private void Form1_Load(object sender, EventArgs e)




private void button1_Click(object sender, EventArgs e)


Process[] notepads = Process.GetProcessesByName("notepad"); if (notepads.Length == 0) return; if (notepads[0] != null)


IntPtr child = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);

SendMessage(child, 0x000C, 0, textBox1.Text);