“Access Denied” on writing on Mailslot in Windows Service program
-
28-10-2019 - |
Вопрос
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 ?
Решение
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;
Другие советы
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:
- A service with the MailSlot (Embarcadero C++ 2010)
- A service with a client mailslot (.NET v4)
- A WPF with a client mailslot (.NET v4)