c++windowsdirent.hsystem32

C++ - How to read system files


I'm trying to find a file that starts with "silabs-cdc" in "C:\\Windows\\System32\\DriverStore\\FileRepository"

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

but on windows vista the opendir always ends up with error as the folder did not exist (but it exists!), windows xp, windows 10 works just fine. I also tried findfirstfile function, but same result.

Is there any system folder protection? Is it possible to get through it - programmatically?

BTW: non system folders works fine, path to the folder is correct

EDIT: running program as admin will do nothing


Solution

  • Based on our comment exchange, 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 or you could build your executable to match the bittedness of the system, as a 64 bit executable will not be subject to redirection.