1

I know this question was asked before over and over, but I couldn´t find a solution that worked for me.

my application needs to do some modification in the program files folders. It starts as a regular user. I found out that adding the app.manifest helps. So here´s part of my code:

ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd.exe";
info.Arguments = @"/c echo abc > ""%programfiles(x86)%\testfile.txt"""
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.WorkingDirectory = @"C:\Temp";

Process proc = new Process();
proc.StartInfo = info;
proc.Start();
Console.WriteLine(proc.StandardOutput.ReadToEnd());
Console.WriteLine(proc.StandardError.ReadToEnd());
proc.WaitForExit();

In my app.manifest this is what is relevant:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

If the user executing the application is a regular user, a UAC prompt will pop up requesting username and password (because of the manifest). Now, if I start the application with an admin user (using psexec for example)...

psexec.exe -u Username -p Password cmd /c myapp.exe

... I thought it would run like a charm, but instead it pops up a slightly different message asking me to confirm that I want the program to run (without fields for username and password). If I say yes, it runs fine.

What I want is that it runs with admin privileges, without any prompt, and without disabling UAC on registry for example. Is that even possible?

Adriano_Pinaffo
  • 1,429
  • 4
  • 23
  • 46
  • Found more info [here](https://stackoverflow.com/questions/24887142/c-sharp-process-disable-user-account-control-prompt) saying this is by design. I may work around by trying to change program files security settings. We´ll see. – Adriano_Pinaffo Jun 07 '17 at 13:16
  • "Is that even possible?" No. That would be a security hole. The entire purpose of UAC is to prompt for permission. All malware would exploit this if you could do it. – Bill_Stewart Jun 15 '17 at 17:29
  • (Note that this is a separate issue from setting different file system or registry permissions at install-time. To do that your installer would need to run elevated initially.) – Bill_Stewart Jun 15 '17 at 17:30

0 Answers0