Domain Builder

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 4 March 2008

Using Windows Scripting Host

Posted on 01:50 by Unknown
You can use Windows Scripting Host on PowerBuilder for many purpose. On sample code below, you can use it to get the network domain, user name and computer name. To do so, you need Windows Scripting Host Object Model component (wshom.ocx)
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 IF


With 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 = 12


You 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
Email ThisBlogThis!Share to XShare to Facebook
Posted in PowerScript | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Using Windows Scripting Host
    You can use Windows Scripting Host on PowerBuilder for many purpose. On sample code below, you can use it to get the network domain, user na...
  • List available ODBC datasources
    You can list available ODBC datasources from within PowerBuilder. You need to declare the following external functions : FUNCTION integer SQ...
  • Sorting Datawindow
    Here's a script to sort datawindow rows when the column header is clicked as in windows explorer. Requirements : Column header should be...
  • Faster Exist Checking in Oracle
    When performing checks in business logic to see if a record is used as part of a foreign key in a child table people often opt for the Selec...
  • Return Code on Application Exit
    Sometime when a PowerBuilder application is called by other program or a shell script, programmer want a return code after exiting the Power...
  • Keeping Column into Array
    With this simple tips you can keep all the column name on DataWindow into an array int colNum, numCols string colName[] numCols = Integer(dw...
  • Julian Date
    Here's a function to calculate Julian Day number for the specified day, month, year. If the year is B.C. it must be negative. /* public...
  • Getting Computer Name
    You can get the computer name from within the application. Declare the Win32 API modul on Declare -> Local External Functions Function bo...
  • Get a list of printers installed
    In this example, we populate a listbox with the printers name /* Get Printer List */ string printers[] int rtn, i, nbPrinters rtn = Registry...
  • Calling Oracle Stored Procs/Functions from PB
    Whenever you want to make a call to an Oracle stored procedure or stored function, a good approach is to first declare it as an external fun...

Categories

  • Database
  • DataWindow
  • PowerScript
  • Win32 API

Blog Archive

  • ▼  2008 (34)
    • ▼  March (14)
      • Retrieve an environment variable
      • Get a list of printers installed
      • List available ODBC datasources
      • How to get the current DBMS, Database or user thro...
      • Sorting Datawindow
      • Hexadecimal to Decimal
      • Julian Date
      • Hiding Application on Windows Taskbar
      • Hiding Desktop and Taskbar
      • Keeping Column into Array
      • Calling Oracle Stored Procs/Functions from PB
      • Re-initializing an Unbounded Array
      • Tracing on Running Application
      • Using Windows Scripting Host
    • ►  February (1)
    • ►  January (19)
Powered by Blogger.

About Me

Unknown
View my complete profile