CreateFile error in Windows7

arul picture arul · May 20, 2009 · Viewed 8.2k times · Source

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

Answer

Billy ONeal picture Billy ONeal · May 20, 2009
  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