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?