I'm writing an app that needs to work every time the computer starts after the user installs it. i tried to do it on the installer calss in the afterInstall event but the installer puts it self to the registry and runs when windows restarts, so I tried to do it with the commited event and got the same results. After that I chenged the commited property installer class to false but then the commited evet dont fire. My last try was to run the app after it installs and then let it write itself to the registry and a strange thing happened it did writh to the registry but no to the place I wanted it to be does anyone know why that is and how can I fix it?
My code:
bool registry = true;
RegistryKey rkSubKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", false);
string[] values = rkSubKey.GetValueNames();
foreach(string name in values)
{
if (name.Equals("appName"))
registry = false;
}
if (registry)
{
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rkApp.SetValue("appName", Application.ExecutablePath.ToString());
DialogResult r = MessageBox.Show("The system now needs to restart your computer whould you like to do it now?", "Restart is needed", MessageBoxButtons.YesNo);
if (r == DialogResult.Yes)
{
System.Diagnostics.Process.Start("ShutDown", "/r");
}
return;
}
mainModule.start();