Under the administrator permissions can be normal Open and read, but in the process of other users (not administrator) can't read, return insufficient permissions (5) ERROR_ACCESS_DEINED,
DWORD dwSize=256;
HANDLE hMap=CreateFileMapping (/* */INVALID_HANDLE_VALUE hFile, NULL, PAGE_READWRITE | SEC_COMMIT, 0, 1024 * 1024, L Global \ \ "" Test");
Int RST=GetLastError ();
If (hMap!=NULL & amp; & RST==ERROR_ALREADY_EXISTS)
{
The CloseHandle (hMap);
HMap=NULL;
}
Char * pszText=NULL;
PszText=(CHAR *) MapViewOfFile (hMap FILE_MAP_ALL_ACCESS, 0, 0, 1024 * 1024);
While (1)
{
Sleep (3000);
}
UnmapViewOfFile (LPCVOID pszText);
The CloseHandle (hMap);
return 0;
Then
HANDLE hMap=OpenFileMapping (FILE_MAP_ALL_ACCESS, TRUE, L Global \ \ "" Test");
If (hMap==NULL)
{
Lstrcpy (Result, L "0");
}
Char * pszText=NULL;
PszText=(CHAR *) MapViewOfFile (hMap FILE_MAP_ALL_ACCESS, 0, 0, 1024 * 1024);
Can't read, GetlastError returns 5
CodePudding user response:
Ah aPSECURITY_DESCRIPTOR pSec=(PSECURITY_DESCRIPTOR) LocalAlloc (LMEM_FIXED SECURITY_DESCRIPTOR_MIN_LENGTH);
if(! PSec)
{
Return GetLastError ();
}
if(! InitializeSecurityDescriptor (pSec, SECURITY_DESCRIPTOR_REVISION))
{
LocalFree (pSec);
Return GetLastError ();
}
if(! SetSecurityDescriptorDacl (pSec, TRUE, NULL, TRUE))
{
LocalFree (pSec);
Return GetLastError ();
}
SECURITY_ATTRIBUTES attr;
Attr. BInheritHandle=FALSE;
Attr. The lpSecurityDescriptor=pSec;
Attr. NLength=sizeof (SECURITY_ATTRIBUTES);