来自 C# 应用程序的 UWF 统一写入过滤器访问

Posted

技术标签:

【中文标题】来自 C# 应用程序的 UWF 统一写入过滤器访问【英文标题】:UWF Unified Write Filter Access from C# Application 【发布时间】:2020-11-20 06:33:00 【问题描述】:

我有一台装有 Windows IOT Enterprise 的 PC,并且想从我的 C# 应用程序中控制(打开或关闭并设置排除项)UWF。 我尝试使用 System.Diagnostics.Process 访问 uwfmgr.exe。我尝试了两种方法,它们在文件名和参数的初始化方面有所不同:

    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");

其余代码相同,贴在下面:

                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);

用户“Test”是另一个具有管理员权限的用户。结果仍然是命令被中止(拒绝访问)。我尝试使用我的登录用户,它也是管理员,但它没有任何区别。

我也尝试以管理员身份启动我的 exe 并获得相同的结果。

对于这个正确的问题有什么解决方案吗?我可以以管理员身份启动统一写入过滤器吗? 提前感谢您的回复。

【问题讨论】:

有点晚了,但也许我用 C# 编写的程序可以帮助您或其他人激活和停用 UWF。 github.com/cregx/uwf-dashboard 【参考方案1】:

这可能是 32/64 位问题。 尝试通过路径 c:\windows\sysnative\uwfmgr.exe 调用它,这将根据您的应用程序架构正确重定向。

在侧节点上:除了直接通过可执行文件调用 uwfmgr 之外,还有一种方法可以通过 WMI 访问它,这也可以让您更轻松地解析输出。有关一些 C# 示例代码,请参阅此问题:How to get registry and file exclusions from UWF using WMI query in C#

【讨论】:

以上是关于来自 C# 应用程序的 UWF 统一写入过滤器访问的主要内容,如果未能解决你的问题,请参考以下文章

C# mvc统一通道使用过滤器

如何在统一 C# 中解析来自 JSON 的数据? [复制]

我在 C# 中写入啥来编辑访问数据库中的数据

在 phpmyadmin 中重新创建用户后:来自 c# 应用程序的“用户 'root'@'name_of_computer' 的访问被拒绝”

如何使用过滤器从 C# 中的访问中选择特定字段

c# 访问 c++ dll 时尝试读取或写入受保护的内存错误