0

I've been working with .NET Core 2.0, and I've come across an issue while trying to launch an app with the UAC prompt.

To do this, I would generally set the Verb property of ProcessStartInfo to 'runas', however the property is apparently undefined.

I found this question: Launch process that needs to trigger UAC in netcore

Within a comment, I found out that .NET Core 2.0 was meant to contain both Verb and Verbs, and the documentation also includes them.

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.verbs?view=netcore-2.0

Is something in my Visual Studio set up incorrectly? Or are these actually still unsupported?

Worth noting, my 'Target framework' is indeed set to '.NET Core 2.0'.

As requested, here is my method:

public static bool CheckOrRequestAdmin(string command)
{
    if (IsRunAsAdmin())
    {
        return true;
    }

    ProcessStartInfo proc = new ProcessStartInfo();
    proc.UseShellExecute = true;
    proc.WorkingDirectory = Assembly.GetEntryAssembly().Location;
    proc.FileName = Assembly.GetEntryAssembly().Location;
    proc.Verb = "runas";
    proc.Arguments = command;

    try
    {
        Process.Start(proc, );
    }
    catch
    {
        // The user refused the elevation.
        // Do nothing and return directly ...
        return false;
    }

    Environment.Exit(0);
    return true;
}
Joel
  • 1,580
  • 4
  • 20
  • 33
  • 1
    Please provide the code, which does not work. On which platforms did you try it ? What is the filename, which you try to start ? – Aedvald Tseh Jan 04 '18 at 04:56
  • Code is now in the original post. I'm on Win10, running in VS2017. As it's a compilation time issue, not runtime, file name shouldn't matter. In this case, it's simply the name of the executable calling the method. – Joel Jan 04 '18 at 05:33

1 Answers1

0

Classic! Found it just after asking.

Although I had Target framework set, I needed to update the Nuget package for .NET Core App, which was still sitting on an old version.

After updating that, worked exactly as expected.

Joel
  • 1,580
  • 4
  • 20
  • 33