Search code examples
c#startupadministration

Run as Administrator in the startup


hey I'm trying to launch an app on the startup I have always done it just fine by using this code :

RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rkApp.GetValue("Folder Locker") == null)
{
    rkApp.SetValue("Folder Locker", Application.ExecutablePath.ToString());
}

But now when I do this:

requestedExecutionLevel level="requireAdministrator" uiAccess="false" 

to start as administrator the app doesn't start on the start up I need help I hope it would be a small problem and not a big deal.


Solution

  • You cannot get an application to run at logon that will elevate and somehow bypass the UAC dialog. That would pretty much defeat the purpose of UAC.

    Your options include:

    • Accepting that the user will be prompted for elevation.
    • Modifying your application so that it does not require elevation. If some operations require elevation, then start a new elevated process to perform those tasks
    • Running your process as service in session 0 where UAC does not apply.