Click here to Skip to main content
11,802,442 members (71,426 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ VC++
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
Edited 17-Jul-11 23:56pm
digimanus at 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
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 18 Jul 2011
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