Einzelnen Beitrag anzeigen

Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 
#5

CreateMemFile und Service-Anwendung [gelöst]

  Alt 23. Mär 2005, 22:38
Zitat von NicoDE:
Zitat von Union:
Und wie mache ich das genau?
Ich habe anno dazumal im Entwickler-Forum ein Beispiel aus dem Platform SDK übersetzt: RegKeyWithFullAccess.
Ich habe es jetzt beim Erzeugen des MMF innerhalb der Service-Anwendung so gelöst:
Delphi-Quellcode:
procedure CreateMemFile;
var
   aSA : TSecurityAttributes;
   aSD : TSecurityDescriptor;
begin
   aSA.nLength := SizeOf(TSecurityAttributes);
   aSA.bInheritHandle := true;
   aSa.lpSecurityDescriptor := @aSd;
   
   InitializeSecurityDescriptor(aSa.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
   // Das ist die massgebliche Zeile, und hier der Parameter nil:
   // If this parameter is NULL, a NULL discretionary ACL is assigned to the security descriptor, allowing all access to
   // the object. The discretionary ACL is referenced by, not copied into, the security descriptor.
   SetSecurityDescriptorDacl(aSa.lpSecurityDescriptor, True, nil, False);

   MemFile := CreateFileMapping($ffffffff, @aSa, PAGE_READWRITE, 0, SizeOf(TSharedData), 'FlexiCom');
   if MemFile = 0 then
   begin
      raise Exception.Create(GetErrTxt(GetLastError));
   end;
   SharedData := MapViewOfFile(MemFile, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TSharedData));

   if SharedData=nil then
   begin
      CloseHandle(MemFile);
      raise Exception.Create(GetErrTxt(GetLastError));
   end;

   SharedData^ := '';
end;
Dadurch wird laut WinApi-Doku Vollzugriff für alle erteilt. Das ist in dem fall auch nicht weiter schlimm, da sich an dem Server, auf dem der Service läuft, eh nur admins anmelden dürfen.

Danke für die Hilfe!
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat