integer li_rc
OleObject ole_wsh
ole_wsh = CREATE OleObject
li_rc = ole_wsh.ConnectToNewObject ( "WScript.Network" )
IF li_rc = 0 THEN
MessageBox ("Domain", string( ole_wsh.UserDomain ))
MessageBox ("User", string( ole_wsh.UserName ))
MessageBox ("Computer", string( ole_wsh.ComputerName ))
END IFWith WSH, you can execute other application from PowerBuilder application. On example below, Notepad will be called by clicking a button from PowerBuilder application
integer li_rc
OleObject ole_wsh
ole_wsh = CREATE OleObject
li_rc = ole_wsh.ConnectToNewObject ( "WScript.Shell" )
ole_wsh.Run ("Notepad")
ole_wsh.AppActivate("Untitled - Notepad")
Sleep (500)
ole_wsh.SendKeys (''Hello from PB")Sleep is a function from Win32 API module with a declaration like this :
Subroutine Sleep (Long dwMilliseconds) Library "kernel32" Alias for "Sleep"You also can run Calculator program and send some key stroke on it
integer li_rc
OleObject ole_wsh
ole_wsh = CREATE OleObject
li_rc = ole_wsh.ConnectToNewObject ( "WScript.Shell" )
ole_wsh.Run("calc")
ole_wsh.AppActivate ("Calculator", 100)
Sleep (1000)
ole_wsh.SendKeys("1{+}")
Sleep (1000)
ole_wsh.SendKeys("2")
Sleep (1000)
ole_wsh.SendKeys("=")
Sleep (1000)
ole_wsh.SendKeys("*4")
Sleep (1000)
ole_wsh.SendKeys("=")
// 1+2 = ( 3, then) * 4 = 12You also can run VBScript from PowerBuilder easily. To do that you need Microsoft Script Control component (msscript.ocx)
OleObject ole_wsh
Integer li_rc, i, j, k
ole_wsh = Create OleObject
li_rc = ole_wsh.ConnectToNewObject ("MSScriptControl.ScriptControl")
ole_wsh.language = "vbscript"
ole_wsh.addcode("function retfnc(s) retfnc = s end function")
ole_wsh.executestatement ('if 1 > 1 then msgbox retfnc("true") else msgbox retfnc("false") end if
0 comments:
Post a Comment