1

I often need to launch external processes so I wrote a convenient method to easily do that. One of these processes needs to trigger UAC in order to ask the user for their permission. I did some research and found that setting the Verb property of the ProcessStartInfo object to runas in addition to setting the UseShellExecute to true should do the trick.

private static void StartProcess(string fileName, string arguments, bool elevated)
{
    var start = new ProcessStartInfo
    {
        UseShellExecute = false,
        CreateNoWindow = true,
        Arguments = arguments,
        FileName = fileName
    };

    if (elevated) 
    {
        start.Verb = "runas";
        start.UseShellExecute = true;
    }

    int exitCode = 0;
    using (var proc = new Process { StartInfo = start })
    {
        proc.Start();
        proc.WaitForExit();
        exitCode = proc.ExitCode;
    }

    if (exitCode != 0)
    {
        var message = string.Format(
            "Error {0} executing {1} {2}",
            exitCode,
            start.FileName,
            start.Arguments);
        throw new InvalidOperationException(message);
    }
}

However, the Verb property is not available in netcore therefore I can't figure out how to achieve the same result. Any suggestion?

Sanket
  • 19,295
  • 10
  • 71
  • 82
desautelsj
  • 3,587
  • 4
  • 37
  • 55
  • You may be aware of this but just thought of sharing again - **both Verb as well as Verbs are coming back as part of .NET Standard 2.0** Refer this - https://github.com/dotnet/docs/issues/1103 – Sanket Jan 02 '17 at 11:08
  • @Sanket thanks for pointing this out. I was not aware. I'll wait for netstandard 2.0. In the mean time, any known workarounds? – desautelsj Jan 02 '17 at 23:03
  • I am not aware of any workaround. – Sanket Jan 03 '17 at 03:13
  • @Sanket if you post your comment as an answer, I'll be glad to accept it. – desautelsj Jan 03 '17 at 03:20
  • I would suggest you to wait for few days... may be someone will post some workaround. – Sanket Jan 03 '17 at 03:23

0 Answers0