简体   繁体   English

.NET组策略\\机器文件夹

[英].NET Group Policy\Machine folder

I have a unique requirement (let's just leave it at that) to access the System32\\GroupPolicy\\Machine folder from C#. 我有一个独特的要求(让我们留在那儿),可以从C#访问System32 \\ GroupPolicy \\ Machine文件夹。 I can browse to the directory with full control, but when accessing from C# I get the following error: 我可以完全控制浏览到该目录,但是从C#访问时出现以下错误:

Could not find a part of the path 'C:\\windows\\system32\\grouppolicy\\Machine'. 找不到路径“ C:\\ windows \\ system32 \\ grouppolicy \\ Machine”的一部分。

I can't use any other traditional methods of accessing policies, it has to be done through the file system. 我不能使用任何其他传统的策略访问方法,必须通过文件系统来完成。 Here's the code I'm using just trying to browse the directory: 这是我尝试浏览目录时使用的代码:

  string[] files;  

files = Directory.GetFiles(Environment.SystemDirectory + @"\\grouppolicy\\Machine");

Running Visual Studio as admin, Win 7 64 bit 以管理员身份运行Visual Studio,Win 7 64位

EDIT 编辑

Directory.GetDirectories(Environment.SystemDirectory + @"\\grouppolicy\\") also returns no folders even though I see 3 subfolders in explorer. 即使我在资源管理器中看到3个子文件夹,Directory.GetDirectories(Environment.SystemDirectory + @“ \\ grouppolicy \\”)也不会返回任何文件夹。

You are almost certainly being redirected to the syswow64 directory due to 32 bit application on 64 bit OS. 由于64位操作系统上的32位应用程序,几乎可以肯定将您重定向到syswow64目录。 (just wasted 3 hours beating my head on the desk same issue). (只花了3个小时就把我的头都打在了桌子上)。 Per MSDN use SYSNATIVE instead of SYSTEM32. 对于每个MSDN,请使用SYSNATIVE而不是SYSTEM32。

Like: 喜欢:

    string[] files;
    if (Environment.Is64BitOperatingSystem)
    {
        files = Directory.GetFiles("C:\\WINDOWS\\SYSNATIVE\\GROUPPOLICY\\MACHINE");
    }
    else
    {
        files = Directory.GetFiles("C:\\WINDOWS\\SYSTEM32\\GROUPPOLICY\\MACHINE");
    }
    foreach (string file in files)
    {
        System.Console.WriteLine(file);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM