Jump to content

Script not working as Scheduled Task


Recommended Posts

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

;===============================================================================
; 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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...