“访问被拒绝”关于在 Windows 服务程序中的 Mailslot 上写入

发布于 2024-12-19 15:26:27 字数 184 浏览 4 评论 0原文

我使用 Mailslots(在 Delphi 7 中)作为程序间对话框,一切正常。

但是,当我使用我的一个程序(在 Windows XP 中)作为 Windows 服务时,当另一个(经典管理员用户的)程序尝试写入邮槽时,我收到一条消息“邮槽访问被拒绝”。 我知道这肯定是一个权限问题,因为服务拥有系统权限,但是......解决方案是什么?

I use Mailslots (in Delphi 7) for inter-programs dialog and all is OK.

But when I use one of my program (in Windows XP) as Windows service I have a message "Mailslot Access Denied", when another (classical admin user's) program try to write to the mailslot.
I Understand that it is surely a rights problem since service have SYSTEM rights but...what is the solution ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻找一个思念的角度 2024-12-26 15:26:27

调用 CreateMailslot() 时,指定一个允许对邮槽进行所有访问的 SECURITY_DESCRIPTOR,例如:

var
  ...
  sd: SECURITY_DESCRIPTOR;
  sa: SECURITY_ATTRIBUTES; 
begin
  ...
  InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION);
  SetSecurityDescriptorDacl(@sd, True, nil, False);

  sa.lpSecurityDescriptor := @sd; 
  sa.bInheritHandle := Frue; 

  ... := CreateMailslot(..., @sa);
  ...
end;

When calling CreateMailslot(), specify a SECURITY_DESCRIPTOR that allows all access to the mailslot, eg:

var
  ...
  sd: SECURITY_DESCRIPTOR;
  sa: SECURITY_ATTRIBUTES; 
begin
  ...
  InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION);
  SetSecurityDescriptorDacl(@sd, True, nil, False);

  sa.lpSecurityDescriptor := @sd; 
  sa.bInheritHandle := Frue; 

  ... := CreateMailslot(..., @sa);
  ...
end;
﹂绝世的画 2024-12-26 15:26:27

我使用C++ Embarcardero 2010,并且我必须对 Remy Lebeau 的解决方案进行一些修改,因为 CreateMailSlot 函数接收SECURITY_ATTRIBUTES * 类型的指针,而不是 SECURITY_DESCRIPTOR * 类型的指针。

我的 C++ 解决方案是:

SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);

SECURITY_ATTRIBUTES sa;
sa.lpSecurityDescriptor=&sd;
sa.bInheritHandle=true;
this->pHandleMailSlot = CreateMailslot("your mail slot path", 0, -1, &sa);

注意:在我的例子中,我有三个应用程序:

  1. 具有 MailSlot 的服务 (Embarcadero C++ 2010)
  2. 具有客户端邮槽的服务 (.NET v4)
  3. 具有客户端邮槽的 WPF (.NET v4)

I use C++ Embarcardero 2010, and I have to do some modifications to the solution of Remy Lebeau because the CreateMailSlot function receive a pointer of type SECURITY_ATTRIBUTES *, and not a pointer of type SECURITY_DESCRIPTOR *.

My solution in C++ is:

SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);

SECURITY_ATTRIBUTES sa;
sa.lpSecurityDescriptor=&sd;
sa.bInheritHandle=true;
this->pHandleMailSlot = CreateMailslot("your mail slot path", 0, -1, &sa);

Note: In my case I've three applications:

  1. A service with the MailSlot (Embarcadero C++ 2010)
  2. A service with a client mailslot (.NET v4)
  3. A WPF with a client mailslot (.NET v4)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文