AutoHotkey Community

It is currently May 27th, 2012, 4:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: February 25th, 2010, 1:39 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:28 pm 
Offline

Joined: April 17th, 2009, 1:50 pm
Posts: 9
Location: Tampa, FL
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.

Code:
/*
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 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


Last edited by e1miran on February 25th, 2010, 5:37 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:29 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.

Code:
#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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:30 pm 
BTW, I'm using Vista 32 bit. Not sure if that would make a difference or not.

DBM


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:30 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
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:
Code:
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


Last edited by None on February 25th, 2010, 7:53 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:39 pm 
Offline

Joined: April 17th, 2009, 1:50 pm
Posts: 9
Location: Tampa, FL
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:42 pm 
Offline

Joined: April 17th, 2009, 1:50 pm
Posts: 9
Location: Tampa, FL
da_boogie_man wrote:
The answer is yes, scripts can run when Computer is locked.


Not all scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:48 pm 
e1miran wrote:
da_boogie_man wrote:
The answer is yes, scripts can run when Computer is locked.


Not all scripts.


Oops. Guess I should have said that differently.

DBM


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 5:51 pm 
Offline

Joined: April 17th, 2009, 1:50 pm
Posts: 9
Location: Tampa, FL
We won't hold it against you... :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 7:36 am 
@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


Report this post
Top
  
Reply with quote  
 Post subject: Very Helpful
PostPosted: February 14th, 2012, 6:33 pm 
I used this script and found it very useful...for a beginner.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2012, 9:50 pm 
Offline
User avatar

Joined: February 17th, 2011, 6:48 pm
Posts: 427
Location: peering out from behind my favorite rock
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Mickers, rbrtryn, Yahoo [Bot] and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group