Windows - como saber se o windows esta locket (bloqueado)

Top  Previous  Next

How can I Determine If the Workstation Is Locked? 

Answer:

 

 

The SwitchDesktop function makes a desktop visible and activates it. This enables the desktop to receive input from the user. The calling process must have DESKTOP_SWITCHDESKTOP access to the desktop for the SwitchDesktop function to succeed. 

 

A call to the OpenDesktop API (using the DESKTOP_SWITCHDESKTOP flag), followed by a call to the SwitchDesktop API (using the handle returned by OpenDesktop) will determine which condition (Locked or not locked) exists (in Windows 2000 or XP), 

 

function IsWorkstationLocked: Boolean; 

var 

  hDesktop: HDESK; 

begin 

  Result := False; 

  hDesktop := OpenDesktop('default'

    0, False, 

    DESKTOP_SWITCHDESKTOP); 

  if hDesktop <> 0 then 

  begin 

    Result := not SwitchDesktop(hDesktop); 

    CloseDesktop(hDesktop); 

  end

end