Question

I've noticed that if the path parameter to the CreateFile function targets \Windows\System32\ the call is failing with the following error code ERROR_PATH_NOT_FOUND.

The file path is correct, I'm the owner of the folder, so the question is why is the call failing? Did MS add special policy forbidding the folder from being accessed?

Sample code:

TCHAR szFile[MAX_PATH];
PathCombine(szFile, g_szSystemDirectory, "settings.ini");

HANDLE hFile = CreateFile(szFile,
                          GENERIC_READ,
                          0,
                          NULL,
                          OPEN_EXISTING,
                          0,
                          NULL);

if (hFile == INVALID_HANDLE_VALUE)
{
    printf("INVALID FILE: %i", GetLastError());
    return FALSE;
}
Was it helpful?

Solution

  1. Can we see some example code?
  2. Have you specified the drive, I.e. "C:\Windows\System32\"
  3. Are you trying to open a file inside system32?
  4. Does this occur on Windows 7 only? and
  5. Why do you need to modify anything inside system32 in the first place?

Billy3

OTHER TIPS

If it's a 32-bit app running on a 64-bit OS, then calling Wow64DisableWow64FsRedirection() before your call to CreateFile will read from "C:\Windows\System32" instead of "C:\Windows\Syswow64", which is probably what's happening to you.

Using Windows XP both administrators/standard accounts don't require administrative rights to obtain a device handles.

This has changed on Vista, Windows 7 (UAC) where you MUST have administrator rights to obtain device handles.

Some solutions are:

  1. Use a service
  2. Use COM elevation moniker
  3. Use Manifest

Note: If you only need to query statistic information from a device this doesn't require administrative rights. When using CreateFile(), specify zero (0) for the dwDesiredAccess parameter.

You're program probably needs to run as Administrator. You'll have to escalate your privileges, even if you are an administrator. Right click when you run the program and click "Run as Administrator", or edit the properties and select always run as administrator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top