I have a PC with Windows IOT Enterprise and would like to control (turn on or off and set exclusions) the UWF from my C# application. I tried to access the uwfmgr.exe with System.Diagnostics.Process. I tried two approaches and they differ in the init of filename and arguments:
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("cmd", /C c:\\windows\\system32\\uwfmgr get-config");
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("c:\\windows\\system32\\uwfmgr.exe", "get-config");
The remaining code is the same and posted below:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/C c:\\windows\\system32\\uwfmgr get-config");
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
startInfo.UserName = "Test";
var s = new System.Security.SecureString();
s.AppendChar('T');
s.AppendChar('e');
s.AppendChar('s');
s.AppendChar('t');
startInfo.Password = s;
process.StartInfo = startInfo;
process.Start();
result = "";
result_error = "";
exc = "";
process.WaitForExit();
result = process.StandardOutput.ReadToEnd();
result_error = process.StandardError.ReadToEnd();
Console.WriteLine(result);
File.WriteAllText("test.txt", result);
The user "Test" is another user with admin rights. The result is still that the command is aborted (access refused). I tried to use my logged in user which is an admin too but it does not make a difference.
I tried to start my exe as admin as well and get the same result.
Is there any solution for that right problem? Can I start the Unified Write Filter as admin?
This could be a 32/64 bit issue. Try to call it via the path
c:\windows\sysnative\uwfmgr.exe
which will redirect correctly depending on your applications architecture.On a sidenode: Besides calling uwfmgr via the executable directly, there is a way to access it via WMI which will also give you easier parseable output. See this question for some C# sample code: How to get registry and file exclusions from UWF using WMI query in C#