开发者

Program start with windows? c#

开发者 https://www.devze.com 2023-04-05 04:46 出处:网络
So, i have builed a winforms that just open a new program. The code that is in the winform is this:(if anyone needs)

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.

  1. I builed a winforms app.
  2. I did a start process.
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号