C++ - 如何读取系统文件

C++ - How to read system files

我正在尝试在 "C:\Windows\System32\DriverStore\FileRepository"

中查找以 "silabs-cdc" 开头的文件
DIR *dir;
struct dirent *ent;
if ((dir = opendir(path.c_str())) != NULL) { // FAILED
    while ((ent = readdir(dir)) != NULL) 
    {
         std::string fln = ent->d_name;
         if(fln.substr(0,10) == "silabs-cdc")
         {
               // I found it
               break;
         }
    }

    closedir(dir);
}

但在 windows vista 上,opendir 总是以错误结束,因为文件夹不存在(但它存在!),windows xp,windows 10 工作正常。我也尝试了 findfirstfile 函数,但结果相同。

有系统文件夹保护吗?是否有可能通过它 - 以编程方式?

顺便说一句:非系统文件夹工作正常,文件夹路径正确

编辑:运行作为管理员的程序什么都不做

基于 , it looks like on Vista, you built a 32 bit executable, but the drivers were installed as 64 bit drivers. The WOW64 redirection facility means that even though you tried to open a path under C:\Windows\System32, you actually opened a path under C:\Windows\SysWOW64. You could explicitly disable the redirection 或者您可以构建您的可执行文件以匹配系统的位,因为 64 位可执行文件不会被重定向。