1

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.

Bopha
  • 3,296
  • 6
  • 25
  • 23
  • have a look at following link: http://stackoverflow.com/questions/7666408/how-to-request-administrator-permissions-when-the-program-starts http://stackoverflow.com/questions/6059615/net-console-app-keeps-crashing http://stackoverflow.com/questions/227187/uac-need-for-console-application – Pushpendra Sep 23 '12 at 08:06
  • thanks for the link. the post suggested to use requireAdministrator in the manifest but I want the executable to run administrator without the prompting dialogbox. – Bopha Sep 24 '12 at 00:43

3 Answers3

2

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.

Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
  • thanks for the respond. I use asInvoker but it does not solve the issue. When I comemt out the code that references a third party DLL, it runs fine but when I dont comment out, it crashes. – Bopha Sep 24 '12 at 00:47
  • That means your third party DLL has to run in elevated mode, so your best option is to run as administrator. Bypassing the UAC prompt without running as administrator is a long complicated process. – Chibueze Opata Sep 24 '12 at 08:22
0

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

Filippo
  • 1
  • 3
0

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.