How to find Computer Screen is Locked or not using Powershell

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Jason Yoder Jason Yoder 3 months ago.

  • Author
    Posts
  • #53202
    Profile photo of Amar Helloween
    Amar Helloween
    Participant

    Hi All,

    I am performing a GUI Based Automation through PowerShell , but the problem I am facing is the script will only run on an interactive session if the machine is locked, it waits to get unlocked. So is there any way to know if the machine is locked and if yes then how to login or make it run, just saying 😛

    Lets have some idea on the this, and see this possibility.

  • #53266
    Profile photo of Dan Potter
    Dan Potter
    Participant

    You want the script only to run while locked?

    Look for EventID=4634 in the eventlog

  • #53274
    Profile photo of Dan Potter
    Dan Potter
    Participant

    1..10 | % {

    $currentuser = gwmi -Class win32_computersystem | select -ExpandProperty username
    $process = get-process logonui -ea silentlycontinue

    if($currentuser -and $process){"computer is locked"}else{"unlocked"}

    start-sleep 5

    }

  • #53338
    Profile photo of Jason Yoder
    Jason Yoder
    Participant

    Amar,

    This question came up a few years ago in one of my Server classes. Here is my posted solution. It is a combination of PowerShell and Advanced Auditing.

    Jason

    http://mctexpert.blogspot.com/2012/10/how-to-determine-if-client-on-your.html

You must be logged in to reply to this topic.