Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program start with windows? c#

Tags:

c#

winforms

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. THANKS ALLOT!

like image 228
Alon M Avatar asked Jul 23 '26 02:07

Alon M


1 Answers

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);
like image 200
Christophe Geers Avatar answered Jul 25 '26 15:07

Christophe Geers