Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open an Event object created by my service from my application

I have created a windows service. Under which I am creating a event "test". I want to use the same event object to be set/reset by my application. But I do not seem to get the Handle of the event object through my app. But can see the Event being listed in the BaseNamed objects.

I think I need to do something with the security Attribute of the create Event.

I am creating this event in my service

CreateEvent(NULL, TRUE, FALSE, TEXT("Test"))

and using OpenEvent in my application.

OpenEvent( EVENT_ALL_ACCESS, TRUE, TEXT("Test"))

Please suggest what changes I would need to make, for my app to get the handle.

update

After Replacing TEXT("Test") with TEXT("Global\\Test"). Still I didn't get the Event object handle. Yes, now at least its recognizing the existence of the event object with the Error return(Access Denied). It was getting a Error return (the system cannot find the file specified) earlier. As I said, I think there is some security aspect here. This is what I found out: As the session creates the Event in Session 0. It cannot be inherited by my application which is being created in Session 1. For that while creating the Event object, I need to specify the security attribute structure with a proper Security Dispatcher to do so. Could somebody tell me how to do so?

like image 278
WIN_SOM_LIV Avatar asked Jan 12 '23 08:01

WIN_SOM_LIV


1 Answers

Try this:

PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); 
InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(psd, TRUE, NULL, FALSE);

SECURITY_ATTRIBUTES sa = {0};
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = psd;
sa.bInheritHandle = FALSE;

HANDLE hEvent = CreateEvent(&sa, TRUE, FALSE, TEXT("Global\\Test"));
LocalFree(psd);

HANDLE hEvent = OpenEvent(SYNCHRONIZE, FALSE, TEXT("Global\\Test"));
like image 107
Remy Lebeau Avatar answered Jan 31 '23 07:01

Remy Lebeau