Roman Voskoboynikov
Roman Voskoboynikov

Reputation: 9

WinUI3 application does not restart with administrator privileges on Windows 11

I’m trying to implement a program restart asking the user for admin rights for the WinUI3 application. The application uses Windows Update API and I need this functionality to allow the user to install updates available on their OS. I have encountered a problem that restarting with administrator privileges only works on Windows 10 devices, but on Windows 11 the application does not restart. Could you please advise me what could be the problem?

As a result, I would like to get the application restarted with administrator privileges on Windows 11. I used this code to restart the program.

var processInfo = new ProcessStartInfo
{
    FileName = Process.GetCurrentProcess(). MainModule.FileName,
    UseShellExecute = true,
    Verb = "runas",
    Arguments = string. Join(" ", Environment.GetCommandLineArgs(). Skip(1))
};

try
{
    var process = Process.Start(processInfo);

if (process != null)
    {
        Process.GetCurrentProcess(). Kill();
    }

return true;
}
catch (System.ComponentModel.Win32Exception)
{
    return false;
}

Upvotes: 0

Views: 51

Answers (0)

Related Questions