hi friends well we all know that if the computer is lock the script gets paused or doesnt works is their a way that even if the computer is lock the scripts still works????? because i have seen few processes which continue to work even if the computer is lock
can a script made to work if the computer is lock??????
Started by
lostworld
, Feb 25 2010 12:39 PM
16 replies to this topic
#1
-
Posted 25 February 2010 - 12:39 PM
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.
BMP referenced in script
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 #Persistent DetectHiddenWindows, On SetTimer,TaskManager 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 QUIT_HOTKEY=~Escape Hotkey,%QUIT_HOTKEY%,ExitSub ; '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! return ButtonOK: Gui, Submit, NoHide If pwd is space { MsgBox, 4112,ERROR, You must set a password. GuiControl,,pwd, GuiControl,,pwdc, GuiControl,Focus,pwd Exit } If pwd <> %pwdc% { MsgBox, 4112,ERROR, The confirmation does not match the password. Please try again. GuiControl,,pwd, GuiControl,,pwdc, GuiControl,Focus,pwd Exit } Gui, Destroy ; AFTER the pwd is set, block inputs WinHide ahk_class Shell_TrayWnd BlockKeyboardInputs("On") BlockMouseClicks("On") BlockInput MouseMove ; DETERMINE size of desktop area to cover SysGet, numOfMonitors, MonitorCount screenX=0 screenY=0 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 return ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ExitSub: IfWinExist, LockUP! WinActivate Else { 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! BlockKeyboardInputs("Off") BlockMouseClicks("Off") BlockInput MouseMoveOff } return 3ButtonCancel: Gui, 2: +AlwaysOnTop Gui, 3:Destroy BlockKeyboardInputs("On") BlockMouseClicks("On") BlockInput MouseMove MouseMove, %mX%,%mX%,0 return 3ButtonOK: Gui, 3:Submit, NoHide If pwdu <> %pwd% { MsgBox, 4112,ERROR, The password you entered is incorrect. Please try again. GuiControl,3:,pwdu, GuiControl,3:Focus,pwdu Exit } ButtonCancel: 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 keys=Space,Enter,Tab,Esc,BackSpace,Del,Ins,Home,End,PgDn,PgUp,Up,Down,Left,Right,CtrlBreak,ScrollLock,PrintScreen,CapsLock ,Pause,AppsKey,LWin,LWin,NumLock,Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadDot ,NumpadDiv,NumpadMult,NumpadAdd,NumpadSub,NumpadEnter,NumpadIns,NumpadEnd,NumpadDown,NumpadPgDn,NumpadLeft,NumpadClear ,NumpadRight,NumpadHome,NumpadUp,NumpadPgUp,NumpadDel,Media_Next,Media_Play_Pause,Media_Prev,Media_Stop,Volume_Down,Volume_Up ,Volume_Mute,Browser_Back,Browser_Favorites,Browser_Home,Browser_Refresh,Browser_Search,Browser_Stop,Launch_App1,Launch_App2 ,Launch_Mail,Launch_Media,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22 ,1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z ,²,&,é,",',(,-,è,_,ç,à ,),=,$,£,ù,*,~,#,{,[,|,``,\,^,@,],},;,:,!,?,.,/,§,<,>,vkBC Loop,Parse,keys, `, Hotkey, *%A_LoopField%, KeyboardDummyLabel, %state% UseErrorLevel Return ; hotkeys need a label, so give them one that do nothing KeyboardDummyLabel: Return } ; ****************************************************************************** ; 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 Return ; hotkeys need a label, so give them one that do nothing MouseDummyLabel: Return } ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ; Timers to handle TaskManager and prevent initiation of Windows locked workstation state TaskManager: IfWinExist, Windows Task Manager WinHide, Windows Task Manager WinClose,Windows Task Manager return MMove: ID := WinExist("A") If ID <> 0 { MouseMove, 5,5,0,R Sleep 2000 MouseMove, -5,-5,0,R } Return
BMP referenced in script
#2
-
Posted 25 February 2010 - 04:28 PM
The answer is yes, scripts can run when Computer is locked. I just made this script and ran it, then locked {Win+L} my computer and it paused/unpaused my Winamp every 10 seconds during that lock.
DBM
#SingleInstance Ignore #Persistent SetTitleMatchMode, 2 SetTimer, PauseUnpause, 10000 Menu, Tray, NoStandard Menu, Tray, Add, Exit, GuiClose Menu, Tray, Default, Exit Return PauseUnpause: IfWinNotExist, Winamp Return ControlSend, ahk_parent, c ; Pause/Unpause return GuiClose: ExitApp Return
DBM
#3
-
Posted 25 February 2010 - 04:29 PM
BTW, I'm using Vista 32 bit. Not sure if that would make a difference or not.
DBM
DBM
#4
-
Posted 25 February 2010 - 04:30 PM
It is posible to make a script work while the computer is locked, But with limitations:
No userinput (Hotkeys won't work)
No Windows can become active while locked
Use Control send to send key strokes
Example of a script that locks the work station and opens notepad and saves a file:
No userinput (Hotkeys won't work)
No Windows can become active while locked
Use Control send to send key strokes
Example of a script that locks the work station and opens notepad and saves a file:
Send #l Sleep 2000 Run Notepad.exe WinWait Untitled - Notepad Sleep 400 ControlSend ,,{Shift Down}h{Shift Up}ello{control down}s{control up}, Untitled - Notepad WinWait Save As Sleep 300 ControlSend, Edit1, Hi ,Save As ControlClick , &Save, Save As Sleep 2000 WinClose ahk_class Notepad
#5
-
Posted 25 February 2010 - 04:30 PM
There are many applications here at work that we use scripts with, and control send does not always work. Particularly applications that use child-windows.
#6
-
Posted 25 February 2010 - 04:39 PM
The answer is yes, scripts can run when Computer is locked.
Not all scripts.
#7
-
Posted 25 February 2010 - 04:42 PM
The answer is yes, scripts can run when Computer is locked.
Not all scripts.
Oops. Guess I should have said that differently.
DBM
#8
-
Posted 25 February 2010 - 04:48 PM
@e1miran thanks a lottttttttttttttt wat a script man jst awesome i will try to modify it according to my use lets c if i make it
@da_boogie_man and @None thanks to you too for the help yesterday None i tried your script and it also works gr8t job
@da_boogie_man and @None thanks to you too for the help yesterday None i tried your script and it also works gr8t job
#10
-
Posted 26 February 2010 - 06:36 AM
I used this script and found it very useful...for a beginner.
#11
-
Posted 14 February 2012 - 05:33 PM
e1miran,
Thanks for sharing your LockUP script; I thought it was interesting.
What happens if you press the Escape key and then rather than enter a password you instead press the Windows key? For me (XP SP3), it opened the Start menu.
Thanks for sharing your LockUP script; I thought it was interesting.
What happens if you press the Escape key and then rather than enter a password you instead press the Windows key? For me (XP SP3), it opened the Start menu.
#12
-
Posted 14 February 2012 - 08:50 PM
This is also an option:
I had a problem running AutoHotKey script on a Windows 2008 server. Everything works perfectly when logged in with Remote Desktop, but as soon as I log out, all scripts stop working. The solution is relatively simple, but unfortunately no-one have mentioned it on this forum before.
My specific requirements were to run a script which activates an FTP client (FileZilla) on my server and then log in and connect to another backup server syncronising the two servers on a weekly basis. This is then scheduled under the Task Scheduler to run automatically once a week.
The problem is that once you log out with remote desktop, then the server is locked and no scripts can run. I have tried various options, including ControlSend and ControlClick commands, but without any success.
The solution is as follows:
Create a batch file with the following commands and save it to the desktop of the workstation you want to keep unlocked:
I have named my file Logoff.bat
START C:\Windows\System32\tscon.exe 0 /dest:console
START C:\Windows\System32\tscon.exe 1 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 3 /dest:console
START C:\Windows\System32\tscon.exe 4 /dest:console
START C:\Windows\System32\tscon.exe 5 /dest:console
Tscon.exe comes standard with your windows installation and is specifically created to leave a Previously-Locked Console Unlocked.
See this link: http://support.microsoft.com/kb/302801
The next time you log in to the workstation with remote desktop, do not log out the normal way, but run you batch file - in my case "Logoff.bat"
This will terminate your Remote Desktop connection and log you out, but will then continue in an unlocked state for any scripts to run as if someone is actually logged in.
Should you log out the normal way with remote desktop, then the workstation will be locked - so ensure to log out with your .bat shortcut on your desktop.
As easy as that!
I had a problem running AutoHotKey script on a Windows 2008 server. Everything works perfectly when logged in with Remote Desktop, but as soon as I log out, all scripts stop working. The solution is relatively simple, but unfortunately no-one have mentioned it on this forum before.
My specific requirements were to run a script which activates an FTP client (FileZilla) on my server and then log in and connect to another backup server syncronising the two servers on a weekly basis. This is then scheduled under the Task Scheduler to run automatically once a week.
The problem is that once you log out with remote desktop, then the server is locked and no scripts can run. I have tried various options, including ControlSend and ControlClick commands, but without any success.
The solution is as follows:
Create a batch file with the following commands and save it to the desktop of the workstation you want to keep unlocked:
I have named my file Logoff.bat
START C:\Windows\System32\tscon.exe 0 /dest:console
START C:\Windows\System32\tscon.exe 1 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 3 /dest:console
START C:\Windows\System32\tscon.exe 4 /dest:console
START C:\Windows\System32\tscon.exe 5 /dest:console
Tscon.exe comes standard with your windows installation and is specifically created to leave a Previously-Locked Console Unlocked.
See this link: http://support.microsoft.com/kb/302801
The next time you log in to the workstation with remote desktop, do not log out the normal way, but run you batch file - in my case "Logoff.bat"
This will terminate your Remote Desktop connection and log you out, but will then continue in an unlocked state for any scripts to run as if someone is actually logged in.
Should you log out the normal way with remote desktop, then the workstation will be locked - so ensure to log out with your .bat shortcut on your desktop.
As easy as that!
#13
-
Posted 08 November 2012 - 07:48 PM
I thought a nice twist to e1miran's version would be to substitute the black screen with a duplicate of the "locked computer" sign on screen (I had it so the password type in box was showing empty which you get by hovering over with the mouse pointer.) , made by performing the 'printscreen' copy-n-paste into mspaint, saving as bitmap and then displaying with a SplashImage with no border, and then having the inputs blocked as suggested.
#14
-
Posted 08 December 2012 - 08:02 PM
Hello All,
ZK7 - You Made My Day - Exactly what I looked for !!!!!
Just wanted to Say - A BIG 10Q.
So simple ..... only one batch file that disconnects.
Regards
Etay G
#15
-
Posted 23 April 2013 - 02:43 PM