Click here to Skip to main content
13,552,926 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have created Event
HANDLE h = CreateEvent(NULL, FALSE, FALSE, "eventname");
And open it in another process
HANDLE h1 = OpenEvent(EVENT_MODIFY_STATE, FALSE, "eventname");

It work fine when I run normally.
But when I have created event in windows service it gives error Access denied while opening event.
Can anybody give sujjection to this problem
Posted 17-Jul-11 23:51pm
Updated 17-Jul-11 23:56pm
digimanus 18-Jul-11 5:54am
under which user runs the windows service?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here is the signature for CreateEvent
  __in_opt  LPSECURITY_ATTRIBUTES lpEventAttributes,
  __in      BOOL bManualReset,
  __in      BOOL bInitialState,
  __in_opt  LPCTSTR lpName

You ave to pass a SECURITY_ATTRIBUTES structure granting access to the user (or a group) that will call OpenEvent.

Take a look at Creating a Security Descriptor for a New Object in C++[^] - it shows how to work with SECURITY_ATTRIBUTES.

Best regards
Espen Harlinn
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I think it has something to do with first parameter LPSECURITY_ATTRIBUTES. in msdn it is suggested "If this parameter is NULL, the handle cannot be inherited by child processes.".

You better try to fix this issue.

MSDN link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180515.1 | Last Updated 18 Jul 2011
Copyright © CodeProject, 1999-2018
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