简体   繁体   English

在Windows Service程序中在Mailslot上写入时“访问被拒绝”

[英]“Access Denied” on writing on Mailslot in Windows Service program

I use Mailslots (in Delphi 7) for inter-programs dialog and all is OK. 我使用Mailslots(在Delphi 7中)进行程序间对话框,一切正常。

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. 但是,当我将其中一个程序(在Windows XP中)用作Windows服务时,会出现一条消息“ Mailslot Access Denied”,而另一个(经典管理员用户)程序尝试写入Mailslot。 I Understand that it is surely a rights problem since service have SYSTEM rights but...what is the solution ? 我知道这肯定是一个权限问题,因为服务具有SYSTEM权限,但是...解决方案是什么?

When calling CreateMailslot() , specify a SECURITY_DESCRIPTOR that allows all access to the mailslot, eg: 调用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;

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

My solution in C++ is: 我在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);

Note: In my case I've three applications: 注意:就我而言,我有三个应用程序:

  1. A service with the MailSlot (Embarcadero C++ 2010) MailSlot的服务(Embarcadero C ++ 2010)
  2. A service with a client mailslot (.NET v4) 带有客户端邮槽的服务(.NET v4)
  3. A WPF with a client mailslot (.NET v4) 具有客户端邮槽(.NET v4)的WPF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM