So,
i have builed a winforms that just open a new program.
The code that is in the winform is this:(if anyone needs)
Process a;
Process a = Process.Start("notepad.exe");
BUT.
i need to know how can i say to the program to start with Windows Start up. Like skype do, or any other program.
So.
- I builed a winforms app.
- I did a start process.
- now i need help with doing that the program will strat with windows.
The only important thing, is that the program will allow me to chose i want her to start with windows or not. so, if anyone give me functions, please, give me on\off functions.开发者_Go百科 THANKS ALLOT!
If you want to automatically start an application on Windows startup you must register it in the Windows Registry.
You need to add a new value to the following registry key:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
which will start the application for the current user
or to the key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
which starts the application for all users
The following example will start the application for the current user:
var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true);
key.SetValue("MyApplication", Application.ExecutablePath.ToString());
Just replace the line second line with
RegistryKey key = Registry.LocalMachine.OpenSubKey(path, true);
if you want to automatically start the application for all users on Windows startup.
If you want to disable this so that the application won't start automatically, just remove the registry value.
var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true);
key.DeleteValue("MyApplication", false);
Since you are asking to run NOTEPAD.EXE you can to it directly by dropping it's icon into the Startup windows folder.
精彩评论