Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically start application on login

Tags:

windows

What's the best way to programmatically start an application on login for Windows? I know you can do it by adding an item to the startup folder in the start menu, but I want to have an option in my application to turn it off and on.

like image 945
Lodle Avatar asked Dec 22 '08 08:12

Lodle


People also ask

How do I change the startup programs in C#?

I make some small changes on your code, you can have a look at it. When you select a Item in ListBox, you can use the following code to disable start up program. StartUpProgram program = listBox1. SelectedItem as StartUpProgram; // remove startup startupKey = Microsoft.


2 Answers

This is how you could do it in C#:

Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
          "MyStartUp",
          @"C:\StartUpApp.exe");

You basically need to add a registry entry. The above one works on start-up. There are a few more. I recommend that you download a tool like Autoruns to see all possible locations.

like image 170
kgiannakakis Avatar answered Oct 29 '22 05:10

kgiannakakis


How about installing your program as a Windows service? Services can be switched between 'disabled', 'manual' and 'automatic', and you can access services from within your code (even from a Java application) and manipulate its state.

Just a thought.

Yuval =8-)

like image 36
Yuval Avatar answered Oct 29 '22 05:10

Yuval