Method 1:
Using Microsoft. Win32;
Private void Form1_Load (object sender, EventArgs e)
{
// Obtain the program execution path ..
String starupPath = Application. ExecutablePath;
// Class Micosoft. Win32.RegistryKey. indicates the entry-level node in the Window registry. This class is installed in the registry.
RegistryKey loca = Registry. LocalMachine;
RegistryKey run = loca. CreateSubKey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run ");
Try
{
// SetValue: name of the stored value
Run. SetValue ("WinForm", starupPath );
MessageBox. Show ("registry added successfully !! "," "Prompt", MessageBoxButtons. OK, MessageBoxIcon. Information );
Loca. Close ();
}
Catch (Exception ee)
{
MessageBox. Show (ee. Message. ToString (), "", MessageBoxButtons. OK, MessageBoxIcon. Error );
}
}
Method 2:
Add it to the Registry and directly write it to the registry using code. You can also manually add it.
E: D: \ tractor.exe // it can be your program name and complete path.
You can also manually drag it to start ....
RegistryKey hklm = Application. LocalMachine;
RegistryKey run = hklm. CreateSubKey (@ "SOFTWARE \ Microsoft \ Windows \ Current \ Version \ Run ");
Try
{
Run. SetValue ("tractor.exe", "D: \ tractor.exe ");
MessageBox. Show ("registry added successfully !! "," Prompt ", MessageBoxButton. OK, MessageBoxIcon. Information );
Hklm. Close ();
}
Catch (Exception ee)
{
MessageBox. Show (my. Message. ToString (), "prompt", MessageBoxButton. OK, MessageBoxIcon. Error );
}