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