CreateFile error on Windows7

I noticed that if the path parameter for a function CreateFile

is targeting \Windows\System32\

, the call is aborted with the following error code ERROR_PATH_NOT_FOUND

.

The file path is correct, I am the owner of the folder, so the question is why is the call not working? Has MS added a special policy to deny folder access?

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

      

0


a source to share


4 answers


  • Can you see some sample code?
  • You specified the drive, Ie "C: \ Windows \ System32 \"
  • Are you trying to open a file inside system32?
  • Does this only happen on Windows 7? and
  • Why do you need to change something inside system32?


Billy3

+2


a source


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



+2


a source


Using Windows XP for both administrators and standard accounts does not require administrative rights to obtain device descriptors.

This changed in Vista, Windows 7 (UAC) where you MUST have administrator rights to get device descriptors.

Some solutions:

  • Use service
  • Use proxy COM-level file
  • Use manifest

Note. If you only need to request statistical information from the device, this does not require administrative rights. If used, CreateFile()

specify zero (0) for the dwDesiredAccess parameter.

+2


a source


You probably need to run the program under the name "Administrator". You will need to increase your privileges even if you are an administrator. Right click when starting the program and select "Run as administrator" or edit the properties and select "Always run as administrator".

0


a source







All Articles