Windows – How to lock screen from command line in Windows 8.1

autohotkeywindows 8.1

The following command is mentioned around other places:

rundll32.exe user32.dll,LockWorkStation

or

C:\Windows\System32\rundll32.exe user32.dll,LockWorkStation

but I couldn't make the command work in cmd.exe (Administrator mode).

In Windows 7, this is how I achieved what I wanted in autohotkey script
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0

Sleep, 500
DllCall("LockWorkStation")
Sleep, 2000
RegWrite, REG_DWORD, HKEY_CURRENT_USER, 
Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1

Best Answer

I tired both the commands manually and it worked for me with out any issues both in normal and admin privileged cmd in 8.1 OS .

rundll32.exe user32.dll,LockWorkStation

or

C:\Windows\System32\rundll32.exe user32.dll,LockWorkStation

check whether it is prompting any error message while executing the command and debug based on the error message

Related Question