Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

can a script made to work if the computer is lock??????

  • Please log in to reply
16 replies to this topic
  • Members
  • 1 posts
  • Last active: Aug 06 2013 07:44 AM
  • Joined: 31 May 2013

10 Points for ZK7... you saved me a day of work... THANKS!!!!!!!!!!

  • Members
  • 1 posts
  • Last active: Jul 07 2014 03:39 PM
  • Joined: 03 Jul 2014

To put it simply when the PC is in a locked state Windows uses a sort of "alternate desktop" which contains no windows.

So, if you have scripts that use commands such as WinWaitActive, WinClose, Send etc., the script will not function correctly because there are no windows that exist in order to be acted upon.

I've gotten around this by creating a script that acts as a psuedo-lock screen. It covers the desktop with a black GUI window and locks out keyboard and mouse input except for one hotkey that allows be to input a password and "unlock" it. It also sends a mouseclick periodically to make sure that the PC doesn't automatically lock due to inactivity. Instead of locking the machine, I run this script. All scheduled scripts are then able to run behind my "locked" desktop.

 When a Windows XP PC is locked by CTRL-ALT-DEL or Win-L, the system does not
 merely initiate a screensaver.  It actually initiates an alternate desktop (the winlogon desktop).
 This alternate desktop has no icons and no application windows can open on it.  Therefore, it is
 not possible for AHK to manipulate windows or send keystrokes and mouseclicks because there is
 no active window when the system is locked.
 LockUP was written as a substitute to Windows' locked workstation state.  LockUP allows the user
 to be compliant by disallowing unauthorized access to the PC, but at the same time allows AHK to manipulate
 windows as needed.  
 The script does the following.
	-- Disables keyboard and mouse inputs
	-- Sets a password to unlock the station
	-- Creates a black colored window that covers the entire desktop
	-- Sends a mousemove every 10 minutes to prevent the system from entering 
	    Windows' locked workstation state.
	-- Handles TaskManager in the event someone tries to enter the system
	    by killing the AHK process.
	-- Handles Remote Desktop lockout.  This is needed because when disconnecting
	    from a remote computer, that machine automatically becomes locked by Windows.
	-- Allows keyboard and mouse unlock via a hotkey combination which presents
	    a GUI requesting the password to kill LockUP.
#NoEnv ; Avoids checking empty variables to see if they are environment variables
DetectHiddenWindows, On
SetTimer,MMove, 600000
FileInstall, locked.bmp,%A_ScriptDir%\locked.bmp

; SET the quit hotkey
; Note: the quit hotkey MUST be based on at least one of these: Control, Shift, Alt

; 'SET pwd' GUI
Gui, Margin,-1,0
Gui, Add, Picture,Section,%A_ScriptDir%\locked.bmp
Gui, Add, Text, Section ym+90 xm+50,This PC is about to be locked.  Please set a password to unlock.`n`nOnce locked, pressing ESC key will allow you to enter the password.
Gui, Add, Text, Section yp+70 ,Password:
Gui, Add, Edit, Password vpwd ys-3 xs+65 w180,
Gui, Add, Text, Section ys+30 xm+50 ,Confirm:
Gui, Add, Edit, Password vpwdc ys-3 xs+65 w180,
Gui, Add, Button, ys+30 xm+240 w75 Default, OK
Gui, Add, Button, ys+30 xm+325 w75, Cancel
Gui, Show, w411 h255, LockUP!

Gui, Submit, NoHide
If pwd is space
	MsgBox, 4112,ERROR, You must set a password.
If pwd <> %pwdc%
	MsgBox, 4112,ERROR, The confirmation does not match the password.  Please try again.
Gui, Destroy

; AFTER the pwd is set, block inputs
WinHide ahk_class Shell_TrayWnd
BlockInput MouseMove

; DETERMINE size of desktop area to cover
SysGet, numOfMonitors, MonitorCount
Loop, %numOfMonitors%
	SysGet, currentMon, Monitor, %A_Index%
	if (currentMonLeft < screenX)
				screenX = %currentMonLeft%
	if (currentMonTop < screenY)
				screenY = %currentMonTop%
SysGet, mX, 78
SysGet, mY, 79

; HIDE cursor
MouseMove, %mX%,%mX%,0

; SHOW Blank Window
Gui, 2:Color, 000000
Gui, 2: +AlwaysOnTop -Caption
Gui, 2:Show, NoActivate w%mX% h%mX% x%screenX% y%screenY%,cover

; HANDLE RDP Lockout
SysGet, rdp, 4096
if rdp <> 0
FileAppend, @`%windir`%\System32\tscon.exe 0 /dest:console,%A_ScriptDir%\rdpdisc.bat
RunWait, %A_ScriptDir%\rdpdisc.bat, ,Hide
FileDelete, %A_ScriptDir%\rdpdisc.bat
; SEND the monitor into off mode
Sleep 500
SendMessage 0x112, 0xF170, 2,,Program Manager


IfWinExist, LockUP!
Gui, 2: -AlwaysOnTop
Gui, 3:Margin,-1,0
Gui, 3:Add, Picture,Section,%A_ScriptDir%\locked.bmp
Gui, 3:Add, Text, Section ym+90 xm+70,This computer is in use and has been locked.`n`nPlease enter the password that was set when the system`nwas locked.
Gui, 3:Add, Text, Section yp+70 ,Password:
Gui, 3:Add, Edit, Password vpwdu ys-3 xs+65 w180,
Gui, 3:Add, Button, ys+30 xm+240 w75 Default, OK
Gui, 3:Add, Button, ys+30 xm+325 w75, Cancel
Gui, 3: +AlwaysOnTop
Gui, 3:+owner2
Gui, 2: -Disabled
Gui, 3:Show, w411 h225, LockUP!
BlockInput MouseMoveOff

Gui, 2: +AlwaysOnTop
Gui, 3:Destroy
BlockInput MouseMove
MouseMove, %mX%,%mX%,0
Gui, 3:Submit, NoHide
If pwdu <> %pwd%
	MsgBox, 4112,ERROR, The password you entered is incorrect.  Please try again.

WinShow ahk_class Shell_TrayWnd
FileDelete locked.bmp
ExitApp ; The only way for an OnExit script to terminate itself is to use ExitApp in the OnExit subroutine.

; Function:
;   The following 2 functions were posted by AHK user Andreone and can be found
;       at http://www.autohotkey.com/forum/topic22761.html
;   BlockKeyboardInputs(state="On") disables all keyboard key presses,
;   but Control, Shift, Alt (thus a hotkey based on these keys can be used to unblock the keyboard)
; Param
;   state [in]: On or Off

BlockKeyboardInputs(state = "On")
   static keys
   Loop,Parse,keys, `,
      Hotkey, *%A_LoopField%, KeyboardDummyLabel, %state% UseErrorLevel
; hotkeys need a label, so give them one that do nothing

; ******************************************************************************
; Function:
;    BlockMouseClicks(state="On") disables all mouse clicks
; Param
;   state [in]: On or Off
BlockMouseClicks(state = "On")
   static keys="RButton,LButton,MButton,WheelUp,WheelDown"
   Loop,Parse,keys, `,
      Hotkey, *%A_LoopField%, MouseDummyLabel, %state% UseErrorLevel
; hotkeys need a label, so give them one that do nothing

; Timers to handle TaskManager and prevent initiation of Windows locked workstation state

IfWinExist, Windows Task Manager
WinHide, Windows Task Manager
WinClose,Windows Task Manager

ID := WinExist("A") 
If ID <> 0
	MouseMove, 5,5,0,R
	Sleep 2000
	MouseMove, -5,-5,0,R
BMP referenced in script



Hello everyone. i was hoping someone could assit with getting this script to work. i'm fairly new to the writing of scripts. i've tired placing this code into AUTOIT and creating an .exe file but i get a lot of errors.