Using Windows Scripting Host In PowerBuilder
Using 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)
Connect Object
1 2 3 4 5 6 7 8 9 10 |
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 |
You also can run VBScript from PowerBuilder easily. To do that you need Microsoft Script Control component (msscript.ocx)
1 2 3 4 5 6 7 |
OleObject wsh Integer li_rc, i, j , k wsh = Create OleObject li_rc = wsh.ConnectToNewObject( "MSScriptControl.ScriptControl" ) wsh.language = "vbscript" wsh.addcode("function retfnc(s) retfnc=s end function") wsh.executestatement ('msgbox retfnc("true")') |
List Windows processes or services You can get the list of the running services by replacing “select * from win32_process” by “select * from win32_service”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
OleObject mssc Int li_rc String ls_code Any res mssc = Create OleObject li_rc = mssc.ConnectToNewObject( "MSScriptControl.ScriptControl" ) mssc.language = "VBScript" ls_code = "function services() ~r~n" + & "strComputer=~".~"~r~n" + & "Set objWMIService = GetObject(~"winmgmts:~"" + & "& ~"{impersonationLevel=impersonate}!\\~"" +& " & strComputer & ~"\root\cimv2~")~r~n" + & "Set colProcesses = objWMIService.ExecQuery(" + & "~"select * from win32_process~" )~r~n" + & "s = ~"~"~r~n" + & "For Each objProcess In colProcesses~r~n" + & " s = s & objProcess.Name & vbCr~r~n" + & "Next~r~n" + & "services = s~r~n" + & "end function" mssc.AddCode(ls_code) res = mssc.Eval("services()") MessageBox("",String(res)) mssc.DisconnectObject() Destroy mssc |
Good Luck!
Subscribe
Login
0 Comments