Search code examples
c#wpfwindowsstartup

How to allow my application to run on Windows startup (or better, user login) without getting blocked from vista/7


I need my application to run on windows startup. I always used registry to do this on windows XP, however in this way I'm getting blocked from vista/7.

How can I avoid this? I can only think about writing a shortcut in startup folder, but I don't know how and I'm not sure if it works.

Are there any guideline I can follow to allow my application to work withot any problems connected with UAC? Expecially related to windows startup in this case

Thanks a lot for any answer

Note: This is a WPF application


Solution

  • Don't know what you mean about Vista/Windows7, but I use folowing code in WPF application and it works on XP/Vista/Win7.

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

    Let me know, if this is not what you're searching for.