Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9177

How to unlock the windows lock screen using powershell

$
0
0

I was trying to unlock the windows lock screen as part of automated testing. Is it possible to unlock it using script. I have a windows 2016 server, where I have locked it and now trying to unlock it using powershell script.

Following are the attempts which I have made and could see still unlocking is not happening.Attempt 1 :

# Define the password$password = "*****"# Unlock the computerAdd-Type -AssemblyName System.Windows.Forms[System.Windows.Forms.SendKeys]::SendWait($password +"{ENTER}") 

Attempt 2:

Add-Type -AssemblyName System.Windows.FormsFunction Unlock-Screen {    Param (        [Parameter(Mandatory=$true)]        [string]$Password    )    # Simulate keyboard input to enter the password    [System.Windows.Forms.SendKeys]::SendWait($Password)    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")}# Call the function with your passwordUnlock-Screen -Password "******"

Attempt 3:

# Define the password to be entered$password = "******"# Create a shell object$shell = New-Object -ComObject "WScript.Shell"# Send Ctrl+Alt+Delete to bring up the login screen$shell.SendKeys("^%{DEL}")# Start-Sleep to wait for the login screen to appearStart-Sleep -Seconds 2# Send the password by typing it$shell.SendKeys("$password")# Send Enter to submit the password$shell.SendKeys("{ENTER}")# Error I receivedException calling "SendWait" with "1" argument(s): "Access is denied"

Please let me know if anyone has achieved this way of working.


Viewing all articles
Browse latest Browse all 9177

Trending Articles