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;
}
a source to share
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.
a source to share
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".
a source to share