【问题标题】:C# accessing winevt directory throws DirectoryNotFoundExceptionC#访问winevt目录抛出DirectoryNotFoundException
【发布时间】:2017-11-12 21:06:02
【问题描述】:

我正在尝试访问我的代码中的目录 C:\Windows\System32\winevt,但我得到了 System.IO.DirectoryNotFoundException

我读过这个帖子: Anyone know why I can't access the winevt folder programmatically in C#?

这意味着在 64 位操作系统下运行 32 位应用程序会将我重定向到 SystemWOW64 目录,解决方法是将我的目录设置为 %windir%\Sysnative\winevt。所以我修改了我的代码以符合上述线程中提供的答案,但它仍然失败。我正在运行 Windows 10 64 位企业版,但 Sysnative 不存在。

示例代码:

这将返回 true:

            string directory = @"C:\Windows\System32";                  
            bool isDirectoryExists = Directory.Exists(directory);

这将返回 false:

            string directory = @"C:\Windows\System32\winevt";                  
            bool isDirectoryExists = Directory.Exists(directory);

System和SysWOW64目录下没有winevt目录,不存在Sysnative。所以我的问题是,我如何访问 winevt 目录?

【问题讨论】:

    标签: c# .net windows io directory


    【解决方案1】:

    我的错误是在 Windows 目录中寻找一个名为 Sysnative 的实际文件夹,我没有看到它,因此假设代码不起作用。但是我还是测试了它,Directory.Exists 返回了 true。这是因为 Sysnative 是一个虚拟文件夹。

    返回真:

            string directory = @"C:\Windows\Sysnative\winevt";                  
            bool isDirectoryExists = Directory.Exists(directory);
    

    http://www.thewindowsclub.com/sysnative-folder-in-windows-64-bit

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-23
      • 2017-09-30
      • 2011-04-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      相关资源
      最近更新 更多