Question

I was wandering if someone could explain to me how I could make my Program run on startup? My program is a C# WCF with a small WPF UI that has to run on a server, and I need to make sure that the program will start whenever that server restarts or for whatever other reason.

I have had a look around, and it appears that I have to use the registry keys but I am not to familiar with how to use registries keys, could someone please explain to me how I could use this. I am using VS2010 with creating an Installer and I would like to set the registry key when it installs :)

P.S. I don't want the application to be a Windows Service, and I can't just put it in the startup folder for a user(cause what if the server restarts and no one logs in?)

Was it helpful?

Solution

Add something to run:

http://www.geekpedia.com/tutorial151_Run-the-application-at-Windows-startup.html

RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());

UPDATE: After thinking about this some more, this probably won't help you because your approach appears to be fundamentally flawed. Somebody still needs to log in order for a UI to run. How about this for a solution:

Push the services back to a windows service (as everyone else has suggested). For the WPF UI piece, separate that from the exe that hosts the WCF services into its own project. Just expose another service endpoint contract that the UI can use to manage / monitor the service.

That opens up the door to being able to monitor the server from a different machine. Also, you don't have to worry about more than one person logging into the server at the same time (a likely scenario in many environments) and spinning up multiple instances of the service host.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top