Einzelnen Beitrag anzeigen

Benutzerbild von Sanchez
Sanchez

Registriert seit: 24. Apr 2003
Ort: Neumarkt Stmk
892 Beiträge
 
Delphi XE6 Enterprise
 
#3

Re: Semaphore für alle Benutzer erzeugen

  Alt 14. Sep 2007, 09:32
Hallo Reinhard,

Danke für die Antwort. Ich hab das mal so getestet, dass ich beide Fehler-Meldungen auswerte. Das hat dann aber auch nicht wie gewünscht funktioniert.
Folgende Zeile aus der Delphi Hilfe hat mir dann aber weitergeholfen:
Zitat:
The name can have a "Global\" or "Local\" prefix to explicitly create the object in the global or session name space. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Namespaces. Fast user switching is implemented using Terminal Services sessions. The first user to log on uses session 0, the next user to log on uses session 1, and so on. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.
Im Endeffekt erreiche ich jetzt mit folgendem Code was ich wollte:

Delphi-Quellcode:
procedure TFrmMain.CheckClientRoleSemaphore;
var desc: SECURITY_DESCRIPTOR;
  aSA : TSecurityAttributes;
begin
  aSA.nLength := SizeOf(TSecurityAttributes);
  aSA.bInheritHandle := true;
  aSa.lpSecurityDescriptor := @desc;

  InitializeSecurityDescriptor(aSa.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
  SetSecurityDescriptorDacl(aSa.lpSecurityDescriptor, True, nil, False);

  VSemaphorHandle := CreateSemaphore( @aSA, 0, 1, PChar('Global\' + SemaphorName + DDBBase.GetDBText));
  if (GetLastError in [ERROR_ALREADY_EXISTS, ERROR_INVALID_HANDLE]) then begin
    if VSemaphorHandle <> 0 then begin
      CloseHandle(VSemaphorHandle);
      VSemaphorHandle := 0;
    end;
    VDoClientRoles := False;
    tmrCheckInstance.Enabled := True;
  end else begin
    VDoClientRoles := True;
    TRoleManager.Instance.LadeRollenAufgaben(RollenAktionErzeugt);
    //neu zeichnen
    InvalidateRect(0, nil, true);
  end;
end;
grüße, daniel
Daniel
Testen ist feige!
  Mit Zitat antworten Zitat