1

I'm setting local auditing policies from a C# .NET program that reads settings from a file then uses Process.Start() with 'cmd' to execute the commands. This way has worked in the past for everything that I've needed it to do (including this exact situation), but recently it's just started to mysteriously fail to set the policies.

Here's the code: (command is of the form "auditpol /set /subcategory:"blah" /success:enable")

ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
string result = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();

In debug in VS2013 it's applying the policies just fine and even on the same computer in the full on .exe it's applying just fine, but when it gets transferred to another computer it will not set the policies from the auditpol command. Anyone have any ideas what could be happening?

Chris Parker
  • 33
  • 1
  • 5
  • Maybe it's not being run as a user with sufficient privileges to make those changes on the other computer? Do the `result` or `error` strings contain any diagnostic messages? What value is the command returning - zero or something else? – nobody Mar 28 '14 at 19:01
  • That's exactly what's happening: It's returning an error "User does not have the required privilege 0x00000522", even though the program is being started by running as administrator. I tried the same thing with UseShellExecute = true and embedding a manifest with requireAdministrator, but that also did not work (though it could have been a different error, couldn't tell with no redirected standarderror and the cmd screen flashing out so quickly). – Chris Parker Mar 28 '14 at 19:16
  • Take a look at the accepted answer to http://stackoverflow.com/questions/133379/elevating-process-privilege-programatically – nobody Mar 28 '14 at 19:21
  • That's the answer that got me to try embedding the manifest and using UseShellExecute = true. Didn't end up getting the command to execute, though, and I couldn't check the error since you can't redirect StandardError with UseShellExecute = true. If you check his edit he also says that something is weird when the guy can't get 'runas' to work (I used that, too). – Chris Parker Mar 28 '14 at 19:41

0 Answers0