[1.0/1.1] Starting up a program automatically when the computer re-boots
Hi. I'm creating a window application and not a service. If it was a service it would start automatically when the computer re-boots. However how do you program your window application to start automatically when the program re-boots?
I know of one way and that is to insert the .exe file in the STARTUP menu in the program list but this is too obvious and the user could delete it by mistake. Is there any other way to enable a window application to start automatically when the computer re-boots?
Jennifer.
I was just researching, is there a way to set a registry key to have your program start up automatically?
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Anything in there should run upon windows startup. The type of value to create in there is a string (shows up as REG_SZ in the values list).
The data is what you want to run (with command line params there too, if your program requires them).
If you want your program to only run once (first time windows is restarted) the put your value in the RunOnce key (or possibly RunOnceEx, not sure which would be best.
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
oK. I checked and found the registry key. Now I do not want to put it there manually. Is there anyway in c# I could set the directory? Either from the setup build or probably everytime the program starts, check to see if its set, and if not, then set it. Is that possible with some pseudocode or some reference?
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
Nobody knows? Does this mean that I cannot do this through a C sharp program?
Jennifer
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
You can create the registry entry with your setup project and you can put code in your app to check for that registry value each time it shuts down, but there is no way for your app to check the registry after it is closed, so if the user deletes the key after your app is shut down then your app will not start with Windows. Getting and setting information from the registry is just a matter of using the Microsoft.Win32.Registry and .RegistryKey classes.
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
I hope this helps
Code:
Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true).SetValue("MyApp",Application.ExecutablePath);
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
Thanks guys, i'll try it out and post back a reply - Jen
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
Hi. I tried it out and it worked. However there is a little problem. I developed a very simple application with a notify icon, when the computer booted, the application started, but not the notify icon. I checked in the processes and the program was started. I tried it again with some applications, and when the computer booted, the program started but the forms didnt display. It seems to me that apparently it is starting before some critical feature necessary to bring up the forms. Anyone knows how to solve this problem?
Jennifer
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
Ok. I found the error but dont know how to solve it. When I have this program, and starts it, it starts fine, but when it starts after a reboot it fails. In my program I am reading a file: file.xml which is located:
@"Files\file.xml"
Now when the program starts from the auto-reboot, what is happenning is that it is not reading the path of the folder where the files exist. So that the path statement is actually:
c:\Documents and settings\Administrator\Files\file.xml
to which it is generating the file does not exist. Now the real path to the application folder is:
c:\Program Files\home\test\bin\debug
in that path, i have a folder called Files and only one file: file.xml.
Apparently it is reading the default path as the desktop.
Originall I had:
Microsoft.Win32.Registry.LocalMachine....
I changed it to:
Microsoft.Win32.Registry.CurrentUser....
but it is not working, the same problem. Wierd problem, why when I say:
@\Files....
It is assuming c:\....\Desktop\Files\file.xml
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
Use
Code:
Application.StartupPath+@"\Files\file.xml";
Re: [1.0/1.1] Starting up a program automatically when the computer re-boots
LOL. that simple huh, Thanks!!!