locked
CreateEvent OpenEvent RRS feed

  • Question

  • Hi all

    I am having problem working win CreateEvent i Visual C++  unmanaged.

    I have 2 applications one is GUI based and the other is service running under Local System account.

    GUI application create an event X, CreateObject(X)

    Service Application do HANDLE myHandle = OpenEvent(X)

    myHandle is NULL and the GetLasetError() return ERROR_FILE_NOT_FOUND.

    So I tought that maybe the OpenEvent called before the CreateEvent so decide to take the easy way out and had an sleep(XXXX) (tried different length of pause) but still myHandle is  NULL. I even did a test did a wait until myHandle become something else then NULL but alas no help there.

    So I changed my code, GUI application still does CreateEvent(X) but theService application also do CreateObject(X). The first time its called the service application handle is still NULL. Then its close it self and try again(process restart) and the Service Application CreateObject(X) is working.

    My question is why?. From the documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724485%28v=vs.85%29.aspx.  The create at one process and then open at the other should work. I will be grateful for any help.

    P.S

    The event is a named event and its creaed with GARNT ACCESS TO ALL at the first application.


    • Edited by Natgel Friday, September 27, 2013 5:18 AM
    Friday, September 27, 2013 5:13 AM

Answers

  • Pay attention to the discussion of namespaces in CreateEvent documentation, and follow the link to Kernel object namespaces article. Your UI application and the service are running in different sessions. Events and other kernel objects are created in a session-local namespace by default, invisible to other sessions. You need to explicitly place the object into a global namespace if you want to share it between sessions.

    Beware denial-of-service attacks: a malicious application might open a handle to the same event (now that its name is globally available) and, say, keep resetting it in a tight loop. That will likely cause your service to malfunction.


    Igor Tandetnik

    Friday, September 27, 2013 9:40 PM

All replies

  • in the GUI application

    create an Event object (manual or auto) based on your requirement,  using the API CreateEvent , dont forget to give a unique name to the event object, and then you can in the service application Open the Event using the OpenEvent, the GUI application should have the same level of access privilages as that of the Local Service. 

    Note : windows service have highest security privilage, see if you can launch the process form the service itself, so that they both have the same privilage (i am guessing).

    if you are new to using CreateEvent and OpenEvent , here's a example

    http://www.codeproject.com/Articles/8211/How-to-use-WIN32-Event-Kernel-Object

    Friday, September 27, 2013 8:57 AM
  • Pay attention to the discussion of namespaces in CreateEvent documentation, and follow the link to Kernel object namespaces article. Your UI application and the service are running in different sessions. Events and other kernel objects are created in a session-local namespace by default, invisible to other sessions. You need to explicitly place the object into a global namespace if you want to share it between sessions.

    Beware denial-of-service attacks: a malicious application might open a handle to the same event (now that its name is globally available) and, say, keep resetting it in a tight loop. That will likely cause your service to malfunction.


    Igor Tandetnik

    Friday, September 27, 2013 9:40 PM