How to start application with Windows (2 Different Ways) - CSharp #2 ~ VBTheory™ Tutorials

Friday, September 19, 2014

How to start application with Windows (2 Different Ways) - CSharp #2


Code:
Create registry:
 RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
 key.SetValue("Tutorial", Application.ExecutablePath);
 key.Close();
 MessageBox.Show("Success");

Remove registry:
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
 key.DeleteValue("Tutorial");
 key.Close();
 MessageBox.Show("Success");

Create file:
File.Copy(Application.ExecutablePath, @"C:\Users\VB\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\tutorial.exe");

Delete file:
File.Delete(@"C:\Users\VB\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\tutorial.exe");



Share