从我的应用程序打开由我的服务创建的 Event 对象 [英] Open an Event object created by my service from my application

查看:57
本文介绍了从我的应用程序打开由我的服务创建的 Event 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 Windows 服务.我正在创建一个事件测试".我想使用相同的事件对象由我的应用程序设置/重置.但是我似乎没有通过我的应用程序获取事件对象的句柄.但是可以看到在 BaseNamed 对象中列出的事件.

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,真的,错误的,TEXT("测试"))

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

并在我的应用程序中使用 OpenEvent.

and using OpenEvent in my application.

OpenEvent(EVENT_ALL_ACCESS,真的,TEXT("测试"))

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

请建议我需要进行哪些更改,以便我的应用获得句柄.

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

更新

TEXT("Test") 替换为 TEXT("Global\\Test") 之后.我仍然没有得到 Event 对象句柄.是的,现在至少它通过错误返回(拒绝访问)识别事件对象的存在.它之前收到错误返回(系统找不到指定的文件).正如我所说,我认为这里有一些安全方面.这是我发现的:当会话在会话 0 中创建事件时.它不能被我在会话 1 中创建的应用程序继承.为此,在创建事件对象时,我需要指定安全属性结构适当的安全调度员这样做.有人能告诉我怎么做吗?

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?

推荐答案

试试这个:

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"));

这篇关于从我的应用程序打开由我的服务创建的 Event 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆