Bopha
Bopha

Reputation: 3416

launch C# exe without prompting UAC on Windows 7

I have C# executable that I want to launch on Windows 7 without the dialogbox asking for run-as-administrator.. So here is my code inside the program that launches the C# executable named testApp.exe.

Process testApp = new Process();
testApp.StartInfo.FileName = "C:\\Program Files\\Common Files\\testApp.exe";
testApp.Start();

I also create the minfest for both programs. app.manifest for testApp.exe and app.manifest for the program that launches testApp.exe, and then I change the following line in both manifest to:

requestedExecutionLevel level="requireAdministrator" uiAccess="false"

When I double click on the testApp.exe to run it, testApp.exe program crashes, but when I run it as administrator, it works fine, no crash. So this behavoir also happens the same when i run the program that launches the testApp.exe, testApp.exe crashes.

I must do something wrong here. Do I need to change the name of the manifest because I use the default names that are generated by visual studio 2010.

thanks.

Upvotes: 1

Views: 11032

Answers (3)

user3542483
user3542483

Reputation: 1

my 50 cents,

instead of adding requestedExecutionLevel level="asInvoker" uiAccess="false" in manifest you can use task scheduler to run almost anything in highest level (Administrator Mode)

source: http://www.liberalcode.com/2014/01/automating-run-as-administrator-from-c.html

although the above post talks about running it remotely, but you can easily change it to run locally.

Upvotes: 0

Filippo
Filippo

Reputation: 1

Use info.Verb = "runas"; // Provides Run as Administrator

Upvotes: 0

Chibueze Opata
Chibueze Opata

Reputation: 10054

Actually you should only be using

requestedExecutionLevel level="requireAdministrator" uiAccess="false"

only when you want to run as administrator.

Change this to:

requestedExecutionLevel level="asInvoker" uiAccess="false"

And you'll be good to go.

Upvotes: 2

Related Questions