WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Check if Computer is Locked or Idle


Is there any way to tell whether or not a computer actually is locked? Here’s a script that can work, as long as:
  1. The computer is configured to use a screensaver.
  2. The workstation is automatically locked any time the screensaver is running.
  3. The “timeout” period has elapsed and the screensaver is actually running. (For example, by default the screensaver doesn’t start up until a computer has been inactive – or locked – for ten minutes.)

If all the above are true, this script can tell you if the computer is locked; it does that by grabbing the executable file name for the screen saver, and then checking to see if that executable file is running (by looking at instances of the Win32_Process class). If the screensaver is running then, by definition, the computer must be locked:

Option 1 - Using WMI

Benefit: It can be run on a remote machine
strComputer = "." ;indicates the local machine
strKeyPath = "Control Panel\Desktop"
ValueName = "ScrnSave.exe"
strValue = RegQueryValue( @REGCURRENT, StrCat(strKeyPath, '[', ValueName,']')) 
strValue = StrReplace(strValue, "\", "\\")
objWMIService = GetObject(StrCat("winmgmts:\\" , strComputer , "\root\cimv2"))
colItems = objWMIService.ExecQuery(StrCat("Select * From Win32_Process Where ExecutablePath ='" , strValue , "'"))
If colItems.Count > 0 Then
    Message("Notice", "The computer is locked.")
Else
    Message("Notice", "The computer is not locked.")
End If

Option 2 - Using SysParamInfo

strKeyPath = "Control Panel\Desktop"
ValueName = "ScrnSave.exe"
strValue = RegQueryValue( @REGCURRENT, StrCat(strKeyPath, '[', ValueName,']')) 

;Windows 2000/XP: Determines whether a screen saver is currently running on the 
;window station of the calling process. Note that only the interactive window station, "WinSta0", can have a 
;screen saver running.
;Value: (i) @TRUE if a screen saver is currently running, or @FALSE otherwise.
ret = SysParamInfo( 114, 0, 0)
If ret
    Message("Notice", "The computer is locked.")
Else
    Message("Notice", "The computer is not locked.")
End If

Article ID:   W16989
File Created: 2007:07:03:14:27:30
Last Updated: 2007:07:03:14:27:30