1

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

  • System files sometimes require elevation to access. That could be your issue. – Irelia Oct 11 '19 at 00:12
  • 3
    Did you build the same way on all systems? `System32` is special; a 32 bit application that tries to open it actually reads from the `SysWOW64` directory (which may not have the directory you're looking for, or it may have a different set of files) unless [you explicitly disable Wow64 redirection](https://learn.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-wow64disablewow64fsredirection). – ShadowRanger Oct 11 '19 at 00:13
  • @ShadowRanger you're the boss, thanks, write the answer <3 –  Oct 11 '19 at 00:25
  • If the program needs elevated privs, used the RunAs to execute the executable as admin. – Eljay Oct 11 '19 at 00:30

1 Answers1

3

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.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • no need to disable redirection, just use `C:\Windows\SysNative`. But it's better to match the bitness of the program anyway – phuclv Oct 11 '19 at 01:46