简体   繁体   中英

ProcessStartInfo Verb runas not working

What is wrong with the following code?

        ProcessStartInfo startInfo = default(ProcessStartInfo);

        startInfo = new ProcessStartInfo(SetupProgramPath)
        {
            UseShellExecute = true,
            Verb = "runas",
            WindowStyle = ProcessWindowStyle.Normal,
            CreateNoWindow = false
        };

        Process.Start(startInfo); 

It is expected to prompt for credentials but nothing shows up. The system has the UAC enabled and not supposed to be changed. I appreciate your help in this one. Thank you in advance.

I have worked this out with the following code

ProcessStartInfo startInfo = default(ProcessStartInfo);

startInfo = new ProcessStartInfo(SetupProgramPath)
{
    UseShellExecute = true,
    Verb = "runas",
    WindowStyle = ProcessWindowStyle.Normal,
    FileName = "msiexec",
    Arguments = "/i \"" + SetupProgramPath + "\"",
    CreateNoWindow = false
};

Process.Start(startInfo); 

If you want to ask the user to enter credentials of a different user, then use "runasuser":

ProcessStartInfo startInfo = new ProcessStartInfo(SetupProgramPath)
{
    UseShellExecute = true,
    Verb = "runasuser",
    WindowStyle = ProcessWindowStyle.Normal,
    CreateNoWindow = false
};

Process.Start(startInfo); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM