0
votes

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?)

1
This is exactly what a windows service is for. So it begs the question...why do you not want to use a windows service?Kirk Woll
pctools.com/guides/registry/detail/109 msdn.microsoft.com/en-us/library/aa266445(v=vs.60).aspx You can write this value into registry when performing install this program.Thinhbk
@KirkWoll Windows Services and UIs are not a good mix. Just putting the UI exe in one of the startup registry location is probably best for GUIs.kenny
@kenny, I dunno. I agree with you on the UI part, but WCF services, if they are not going to be hosted in IIS, should be hosted in a windows service.Kirk Woll

1 Answers

5
votes

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.