jamief00 Posted May 22, 2012 Share Posted May 22, 2012 The following script works perfectly when run on a machine with the screen unlocked. However when running as a scheduled job, or running on a remote machine and then disconnecting means it doesn't work properly (the script stops working at the _MouseClickPlus calls (i.e. they don't work). Not sure why they don't work when the screen is locked as they look to be using standard user32.dll calls? Dim $backofficeUser $backofficeUser = "Backoffice [" & StringUpper(@UserName) &"]" ;MsgBox(0, "1", $backofficeUser) ;MsgBox(0, "1", @UserName) Run ("C:\Program Files\WMS\LISA\LISABOff.exe") ;WinWaitActive("Logon - Backoffice") Sleep(5000) ControlClick("Logon - Backoffice", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]") ;WinWaitActive($backofficeUser) Sleep(5000) AutoItSetOption("MouseCoordMode",0) _MouseClickPLus($backofficeUser, "left", 56, 858, 1) Sleep(1000) ControlFocus ( $backofficeUser, "", "[CLASS:SSListbarWndClass; INSTANCE:1]" ) Sleep(1000) _SendMouseMove($backofficeUser, 67, 410) Sleep(1000) _SendMouseMove($backofficeUser, 67, 411) Sleep(2000) ControlClick($backofficeUser, "", "[CLASS:SSListbarWndClass; INSTANCE:1]", "left", 1, 67, 410) _MouseClickPLus($backofficeUser, "left", 67, 410, 1) ;WinWaitActive($backofficeUser) sleep(10000) ControlClick($backofficeUser, "", "[CLASS:ListView20WndClass; INSTANCE:3]", "left", 1, 196, 29) ControlClick($backofficeUser, "", "[CLASS:ThunderRT6CheckBox; INSTANCE:7]") ControlClick($backofficeUser, "", "[CLASS:ThunderRT6CheckBox; INSTANCE:8]") ControlClick($backofficeUser, "", "[CLASS:ThunderRT6CommandButton; INSTANCE:3]") ;WinWaitActive("Price Feed Update") sleep(2000) ControlClick("Price Feed Update", "", "[CLASS:Button; INSTANCE:1]") ;OK Button ;ControlClick("Price Feed Update", "", "[CLASS:Button; INSTANCE:2]") ;Cancel Button _MouseClickPLus is expandcollapse popup;=============================================================================== ; Function Name: _MouseClickPlus() ; Version added: 0.1 ; Description: Sends a click to window, not entirely accurate, but works ; minimized. ; Parameter(s): $Window = Title of the window to send click to ; $Button = "left" or "right" mouse button ; $X = X coordinate ; $Y = Y coordinate ; $Clicks = Number of clicks to send ; Remarks: You MUST be in "MouseCoordMode" 0 to use this without bugs. ; Author(s): Insolence <insolence_9@yahoo.com> ;=============================================================================== Func _MouseClickPlus($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1) Local $MK_LBUTTON = 0x0001 Local $WM_LBUTTONDOWN = 0x0201 Local $WM_LBUTTONUP = 0x0202 Local $MK_RBUTTON = 0x0002 Local $WM_RBUTTONDOWN = 0x0204 Local $WM_RBUTTONUP = 0x0205 Local $WM_MOUSEMOVE = 0x0200 Local $i = 0 Select Case $Button = "left" $Button = $MK_LBUTTON $ButtonDown = $WM_LBUTTONDOWN $ButtonUp = $WM_LBUTTONUP Case $Button = "right" $Button = $MK_RBUTTON $ButtonDown = $WM_RBUTTONDOWN $ButtonUp = $WM_RBUTTONUP EndSelect If $X = "" Or $Y = "" Then $MouseCoord = MouseGetPos() $X = $MouseCoord[0] $Y = $MouseCoord[1] EndIf For $i = 1 To $Clicks DllCall("user32.dll", "int", "PostMessage", _ "hwnd", ControlGetHandle($Window, "", "[CLASS:SSListbarWndClass; INSTANCE:1]") , _ "int", $WM_MOUSEMOVE, _ "int", 0, _ "long", _MakeLong($X, $Y)) DllCall("user32.dll", "int", "PostMessage", _ "hwnd", ControlGetHandle($Window, "", "[CLASS:SSListbarWndClass; INSTANCE:1]"), _ "int", $ButtonDown, _ "int", $Button, _ "long", _MakeLong($X, $Y)) DllCall("user32.dll", "int", "PostMessage", _ "hwnd", ControlGetHandle($Window, "", "[CLASS:SSListbarWndClass; INSTANCE:1]"), _ "int", $ButtonUp, _ "int", $Button, _ "long", _MakeLong($X, $Y)) Next EndFunc ;==>_MouseClickPlus Func _SendMouseMove($Window, $X = "", $Y = "", $Speed = 10) Local $WM_MOUSEMOVE = 0x0200 Local $WinHandle = WinGetHandle($Window) Local $i = 0 Local $MouseCoord = MouseGetPos() $StartX = $MouseCoord[0] $StartY = $MouseCoord[1] If $X = "" OR $Y = "" Then $X = $MouseCoord[0] $Y = $MouseCoord[1] EndIf $StopX = $X $StopY = $Y If $Speed > 0 Then $JumpX = ($StopX - $StartX) / $Speed $JumpY = ($StopY - $StartY) / $Speed For $i = 1 to $Speed $X = $X + $JumpX $Y = $Y + $JumpY $lCoords = _MakeLong($X, $Y) __SendMessageCall($WinHandle, $WM_MOUSEMOVE, 0, $lCoords) Sleep(10) Next EndIf $lCoords = _MakeLong($StopX, $StopY) __SendMessageCall($WinHandle, $WM_MOUSEMOVE, 0, $lCoords) EndFunc And _SendMouseMove is expandcollapse popupFunc _SendMouseMove($Window, $X = "", $Y = "", $Speed = 10) Local $WM_MOUSEMOVE = 0x0200 Local $WinHandle = WinGetHandle($Window) Local $i = 0 Local $MouseCoord = MouseGetPos() $StartX = $MouseCoord[0] $StartY = $MouseCoord[1] If $X = "" OR $Y = "" Then $X = $MouseCoord[0] $Y = $MouseCoord[1] EndIf $StopX = $X $StopY = $Y If $Speed > 0 Then $JumpX = ($StopX - $StartX) / $Speed $JumpY = ($StopY - $StartY) / $Speed For $i = 1 to $Speed $X = $X + $JumpX $Y = $Y + $JumpY $lCoords = _MakeLong($X, $Y) __SendMessageCall($WinHandle, $WM_MOUSEMOVE, 0, $lCoords) Sleep(10) Next EndIf $lCoords = _MakeLong($StopX, $StopY) __SendMessageCall($WinHandle, $WM_MOUSEMOVE, 0, $lCoords) EndFunc Func __SendMessageCall($WinHandle, $iAction, $iParam, $lCoords) DllCall("user32.dll", "int", "PostMessage", _ "hwnd", $WinHandle, _ "int", $iAction, _ "int", $iParam, _ "long", $lCoords) EndFunc Func _MakeLong($LoWord, $HiWord) Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF)) EndFunc ;==>_MakeLong To my knowledge this should work whether the screen is locked or not, as it is using low-level user32 calls. Can anyone see why it would stop working at the _MouseClickPLus($backofficeUser, "left", 67, 410, 1) line? Thanks. Link to comment Share on other sites More sharing options...
lowray1975 Posted May 22, 2012 Share Posted May 22, 2012 Look here: http://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F Link to comment Share on other sites More sharing options...
jamief00 Posted May 30, 2012 Author Share Posted May 30, 2012 Look here: http://www.autoitscript.com/wiki/FAQ#Why...y_script_work_on_a_locked_workDid you bother to read my post? I'm well aware of what happens when the screen is locked, which is why I'm using _SendMouseMove. Link to comment Share on other sites More sharing options...
spudw2k Posted May 30, 2012 Share Posted May 30, 2012 (edited) "Normally, scheduled tasks run as background processes. You can, however, set tasks to run interactively."http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspxhttp://technet.microsoft.com/en-us/library/bb726974.aspxBe sure it is interactive or run as the logged in user. Edited May 30, 2012 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Zedna Posted May 30, 2012 Share Posted May 30, 2012 You can download AutoIt 3.1.0 sources and look at ControlClick() source ... There is done AttachThreadInput and I think it may be reason why your solution doesn't work. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now