0

Well I have a trayIcon program that requires administrator permission to run, I will like to create an option to start the program at system boot.

This is what I have tried:

        try
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            Assembly curAssembly = Assembly.GetExecutingAssembly();
            key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
        }
        catch
        { }

and this one

        RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        string path = Application.ExecutablePath.ToString();
        reg.SetValue("AMD Service Closer", "\"" + path + "\"");

Both are working since they add the registry key:

enter image description here

But when I restart, shutdown or whatever my computer it doesn't start the program. What am I doing wrong?

Rotary Heart
  • 1,899
  • 3
  • 29
  • 44
  • Possible duplicate http://stackoverflow.com/questions/5427673/how-to-run-a-program-automatically-as-admin-on-windows-startup – Martheen Jul 21 '13 at 20:15
  • You cannot expect the user to make an informed decision when the UAC prompt is displayed without the user asking for it. Actively suppressed at startup. Don't try to find a workaround for it, your user won't appreciate it. Consider starting a second EXE that is launched only when needed, a service is boilerplate. – Hans Passant Jul 21 '13 at 20:22
  • But this is not a service, its just a tray app that when clicked it close\kill one service. That's why it need administrator permissions. – Rotary Heart Jul 21 '13 at 20:47

0 Answers0