Click here to Skip to main content

AlexeyLoire asked:

Open original thread
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];
  //Creation of SID for the Everyone group
  if(!AllocateAndInitializeSid(
    &SIDAuthWorld,   //PSID_IDENTIFIER_AUTHORITY
    1,               //nSubAuthorityCount
    SECURITY_WORLD_RID,     //nSubAuthority0
    0, 0, 0, 0, 0, 0, 0,    //Not used subAuthorities.
    &pEveryoneSID))         //Callback argument that recieves pointer to the allocated and initialized SID structure
  {
    LogMakeRecord(L"AllocateAndInitializeSid() Error.");
  }
 
  //Filling in EXPLICIT_ACCESS structure. Everyone's group members will have all the permissions on event.
  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_GROUP;
  ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
  ea[0].Trustee.ptstrName = (LPTSTR)pEveryoneSID;
 
  //Creation of new ACL that contains the new ACE.
  dwRes = SetEntriesInAcl(1, ea, NULL, &pAcl);
  if(dwRes != ERROR_SUCCESS)
  {
    LogMakeRecord(L"SetEntriesInAcl() Error.");
  }
 
  //Security Descriptor initialization
  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.");
  }
  
  //Adding ACL to Security Descriptor.
  if(!SetSecurityDescriptorDacl(pSD, TRUE, pAcl, FALSE))
  {
    LogMakeRecord(L"SetSecurityDescriptorDacl() Error.");
  }
  
  //Initialize Security Attributes structure.
  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.
Tags: C++, Events

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100