JimDel
JimDel

Reputation: 4359

Elevating a process to run as admin doesn't work

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

Upvotes: 2

Views: 1779

Answers (2)

Michael
Michael

Reputation: 199

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);

Upvotes: 1

Remus Rusanu
Remus Rusanu

Reputation: 294237

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.

Upvotes: 1

Related Questions