Hey there, everyone.
While workin on my app i stuck with quite a problem: Application consists of two parts. Service and GUI. GUI while finishing work with data needs to set named global event into alerted state but it does not for some reason. Named Global Event is created by Service. And everything looks fine(no errors during creation)
Event at first was created with default SECURITY_ATTRIBUTES. But when i try openning Event from GUI application a recieve error 5 (ERROR_ACCESS_DENIED).
Then i tried with filled SECURITY_ATTRIBUTES structure and now i get error 2 (ERROR_FILE_NOT_FOUND).
Service part:
#define UI_ACTION_EVENT L"Global\\APPLICATION_GLOBAL_EVENT"
DWORD dwRes;
SECURITY_ATTRIBUTES sa;
PSECURITY_DESCRIPTOR pSD = NULL;
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
PACL pAcl = NULL;
PSID pEveryoneSID = NULL;
EXPLICIT_ACCESS ea[1];
if(!AllocateAndInitializeSid(
&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID)) {
LogMakeRecord(L"AllocateAndInitializeSid() Error.");
}
ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
ea[0].grfAccessPermissions = EVENT_ALL_ACCESS;
ea[0].grfAccessMode = SET_ACCESS;
ea[0].grfInheritance = NO_INHERITANCE;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR)pEveryoneSID;
dwRes = SetEntriesInAcl(1, ea, NULL, &pAcl);
if(dwRes != ERROR_SUCCESS)
{
LogMakeRecord(L"SetEntriesInAcl() Error.");
}
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (pSD == NULL)
{
LogMakeRecord(L"LocalAlloc() Error.");
}
if(!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
{
LogMakeRecord(L"InitializeSecurityDescriptor() Error.");
}
if(!SetSecurityDescriptorDacl(pSD, TRUE, pAcl, FALSE))
{
LogMakeRecord(L"SetSecurityDescriptorDacl() Error.");
}
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
HANDLE hUIActionEvent = CreateEvent(&sa, TRUE, FALSE, UI_ACTION_EVENT);
GUI part:
#define UI_ACTION_EVENT L"Global\\APPLICATION_GLOBAL_EVENT"
HANDLE uiEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, UI_ACTION_EVENT);
if (uiEvent != NULL)
{
if (SetEvent(uiEvent) == 0)
{
ASSERT(FALSE);
#ifdef _DEBUG
DWORD error = GetLastError();
error = error;
#endif
}
}
else
{
#ifdef _DEBUG
DWORD error = GetLastError();
error = error;
#endif
}
The goal is: to make global event accessible to EveryOne group on pc.
I've tried searching similar posts on the internet but had no luck with it.
Looking forward to hearing from ya guys.