WMI: How do I detect is the windows session is locked?

Discussion in 'Scripting' started by WMI_Newbie, Sep 16, 2005.

  1. WMI_Newbie

    WMI_Newbie Guest

    I have used the Scriptomatic generated code (enhanced for VB6) and I always
    get objItem.IsLocked = <Nothing>. Does anyone know how to tell when a user
    has locked the session (i.e. <ctrl-alt-delete> then press "Lock Computer")?



    On Error Resume Next
    Dim objWMIService As Object
    Dim colItems As Object
    Dim objItem As Object
    Timer1.Enabled = False

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from
    Win32_DesktopMonitor", , 48)
    For Each objItem In colItems
    AddText CStr(Now) & " "
    AddText "Name: " & objItem.Name & " "
    AddText "IsLocked: "
    AddText objItem.islocked
    If objItem.islocked Is Nothing Then
    AddLine "<Nothing>"
    AddLine VarType(objItem.islocked)
    End If
    WMI_Newbie, Sep 16, 2005
    1. Advertisements

  2. Jonathan Liu [MSFT], Sep 16, 2005
    1. Advertisements

  3. WMI_Newbie

    WMI_Newbie Guest

    I modified the script in the article to post the time and the message("the
    computer is locked" or "the computer is not locked") to a text box, it always
    returns "The computer is locked." even after I locked the computer. Any
    suggestions? (running W200 Pro)
    WMI_Newbie, Sep 16, 2005
  4. Make sure that you do not have the "Display Properties" dialog opened to the
    Screen Saver tab. This will launch the screensaver and it will show up in
    the process list.

    This technique below is not the most ideal way of doing this. A computer
    may be locked but have no screensaver selected.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    Jonathan Liu [MSFT], Sep 16, 2005
  5. WMI_Newbie

    WMI_Newbie Guest

    I truely am a newbie. I had left the StrComputer = "crowtrobot" instead of
    "." for the local machine. It works now that I have changed it. Thanks for
    your help!
    WMI_Newbie, Sep 16, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.