I've made an application which needs to run a certain process at Windows startup. I've created a method which does it by receiving the path to the program and adding it to the registry. This is the method:
private void AddPathToStartUpPrograms(string path)
{
string startUpPosition1 = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
string startUpPosition2 = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
RegistryKey k = Registry.LocalMachine.OpenSubKey(startUpPosition1, true);
if (k != null)
{
k.SetValue("service", path);
}
k = Registry.LocalMachine.OpenSubKey(startUpPosition2, true);
if (k != null)
{
k.SetValue("service", path);
}
}
This code is working but the problem is that it seems that the process I'm adding make the desktop loading get stuck. When the desktop is loading it loads the background wall paper but the icons won't load. I can get to the task manager and when I close the process I've added to the start up programs, the desktop "unfreeze" and finishes loading everything.
What is strange that even though I close the process, after the desktop finish loading, my process runs again and then everything is ok, meaning it for some reason run itself twice.
So my question is how do I set the process to run only AFTER the desktop finished loading?