Reputation: 41
I am working on a project that must be run at Windows start up,
I have tried to use:
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rkApp.SetValue("1234", path + @"\xxxx.exe");
rkApp.Close();
It starts with Windows but crashes immediately ("application has stopped working windows is checking...".
When I try to debug it, it doesn't crash.
How can I resolve it?
Upvotes: 1
Views: 1977
Reputation: 7452
"Application Crashing" means you have an unhandled exception %90 of the time. You need to log what that exception is to have any hope of solving this.
Upvotes: 0
Reputation: 1048
Access to the registry is under security control. Check that the branch that you are posting to is writeable for the user that your application is running as.
Upvotes: 0
Reputation: 942399
Don't guess at this, write code that helps you diagnose unhandled exceptions. Write an event handler for the AppDomain.CurrentDomain.UnhandledException event and log or display the value of e.ExceptionObject.ToString(). The stack trace you'll get will help you quickly diagnose the cause. I would guess at your code bombing because the app's default directory is not set where it is when you debug. Use full path names for files (i.e c:\foo\bar.txt, not bar.txt).
Upvotes: 6
Reputation: 2547
check if you have delay timer to keep the service running. If there is no work for the service, it will start and stop immediately. Try to log events into eventlogger.
Upvotes: 1