WinBatch question (like vb script or WIL)

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

WinBatch question (like vb script or WIL)

Postposted on Wed Feb 08, 2012 2:42 am

So rather re-write some very crusty vb6 legacy code to include parameterization via the cmd. We're opting to use a scripting language (WinBatch) to send keystrokes/mouse clicks/etc to automate running a program (we'll call it foobar.exe). Source code below:

automate.wbt
Code: Select all
AddExtender("wwctl44i.dll")

;--- credentials ---
if param0 < 3
  Message("Warning","You need to provide all 3 parameters (ie: username password dsn)")
  Exit
else
  username = param1
  password = param2
  dsn      = param3
endif

CurrentDir = DirHome()
cmd        = Environment("COMSPEC")
Run(cmd, "/c %CurrentDir%foobar.exe")

;--- login window ---
myResult = WinWaitExist("~Login", 10)
If myResult == 0
    Message("Error", "Login Error")
    Exit
EndIf
parentHwnd = DllHwnd('~Login')

cSetFocus(parentHwnd)
SendKeysTo("~Login", "%username%{tab}%password%{tab}%dsn%")

btnObject = cWndbyclass(parentHwnd, 'Button') ;OK
cClickButton(btnObject)
TimeDelay(1)

;--- other window ---
myResult = WinWaitExist("~Other Window", 10)
If myResult == 0
    Message("Error", "Other Window Error")
    Exit
EndIf
parentHwnd = DllHwnd("~Other Window")

;--- old way, works, but not as intended ---
;childObject1 = cWndbyid(parentHwnd,    5) ;ThunderRT6PictureBoxDC
;childObject2 = cWndbyid(childObject1, 10) ;update
;childObject2 = cWndbyid(childObject1,  9) ;close
;cClickButton(childObject2)

;--- better way, keepin' it simple stupid ---
SendKeysTo("~Other Window", "!u")          ;sends alt-u (update) key

;--- ok/close window ---
;TimeDelay(1)
;SendKey("~") ;sends {enter} key

Exit


So far this works amazingly successful, market it! sell it! lol j/k... But towards the end, while running the program (the update sql part), it fails (the exe), and pretty much halts the automation script (the wbt file).
thegleek
Darth Gerbil
Gold subscriber
 
 
Posts: 7367
Joined: Tue Jun 10, 2003 11:06 am
Location: Detroit, MI

Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 0 guests