Elevating a process to run as admin doesn't work
-
05-07-2019 - |
Question
Elevating a process to run as admin doesn't work. If I run that application from an elevated command prompt it runs fine. But my code below doesn't.
Process setupws = new Process();
setupws.StartInfo.FileName = @"setupws.exe";
setupws.StartInfo.Verb = "runas";
setupws.StartInfo.UseShellExecute = true;
setupws.Start();
setupws.WaitForExit();
The setupws.exe file runs fine, just not as an admin.
What am I doing wrong?
Thanks
PS. I've also used highestAvailable and requireAdministrator in my app.manifest file
Solution
You need to mark your installer as requestedExecutionLevel level=requireAdministrator in the manifest, see Create and Embed an Application Manifest (UAC).
PS. The requireAdministrator should be in the setupws.exe's manifest.
OTHER TIPS
Have you ran your app as admin and tried it that way? You could do something like:
using System.Security.Permissions;
var mine = new EnvironmentPermission(PermissionState.Unrestricted);
mine.AddPathList(EnvironmentPermissionAccess.AllAccess, Environment.CurrentDirectory);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow