Purpose You want to call up a VBScript function from JavaScript We generally suggest you use JavaScript or VB.NET exits in GuiXT instead of VBScript. See JavaScript, VBScript or VB.NET? for a comparison of the three options. However, for some tasks VBScript does make sense, since one can find plenty of VBScript samples in the web. |
Solution You may use the following JavaScript functions for this purpose: JavaScript framework // vbs.js // Execute VBScript from JavaScript via scripting host // execute expression and return result function vbsExecute(source,textid) { var result = getSH().Eval(source); if (textid) { guixt.setText(textid,result); return ""; } else { return result; }; } // add VBScript functions function vbsAddCode(textid) { var source = guixt.getText(textid); getSH().AddCode(source); } // create scripting host var scriptingHost = null; function getSH() { if (!scriptingHost) { scriptingHost = guixt.CreateObject("MSScriptControl.ScriptControl"); scriptingHost.Language = "VBScript"; scriptingHost.AllowUI = true; scriptingHost.TimeOut = 60000; }; return scriptingHost; }
Example 1 // determine name of month CallJS monthname = vbsExecute "MonthName(8)" // display the result (test) ![]() Example 2
// to scripting host // call up the VBScript function // display the result
(test) ![]() Example 3
We also offer an "Excel" button which downloads the data to a CSV
file, and a filter button which shows all processes with a CPU activity
since the last display.
Pushbutton (1,68) "@42@Refresh" size=(1,15) process="read_processes.txt"Pushbutton (1,92) "@J2@Excel" size=(1,15) process="excel_processes.txt" Pushbutton (1,116) "@4G@Active" size=(1,15) process="active_processes.txt" // create process table CreateTable V[proc] _ ProcessId NameLower Name CreationDate WorkingSetSize Priority _ UserModeTime KernelModeTime _ ReadOperations WriteOperations WriteTransfers _ HandleCount CommandLine endif if V[computername]// process table of selected computer table (3,14) (37,250) name="proc" _ title="&V[proc.rowcount] processes on &V[computername]" _ fixedColumns="12" -rowSelection column "Name" name="Name" size=30 -readOnly column "PID" name="ProcessId" size=10 -readOnly column "Start time" name="CreationDate" size=20 -readOnly column "WorkingSetSize" name="WorkingSetSize" size=16 -readOnly -alignRight column "Priority" name="Priority" size=10 -readOnly -alignRight column "UserModeTime" name="UserModeTime" size=16 -readOnly -alignRight column "KernelModeTime" name="KernelModeTime" size=16 -readOnly -alignRight column "ReadOperations" name="ReadOperations" size=16 -readOnly -alignRight column "WriteOperations" name="WriteOperations" size=16 -readOnly -alignRight column "WriteAmount" name="WriteTransfers" size=16 -readOnly -alignRight column "HandleCount" name="HandleCount" size=12 -readOnly -alignRight column "CommandLine" name="CommandLine" size=68 -readOnly endif InputScript "read_processes.txt" // computer selected? Return "W: Please select a computer" -statusline endif // install VBScript code Set V[proc_code_added] "X" // Read VBScript code from a .vbs file CopyText fromFile="C:\temp\processes.vbs" toText="code" // to scripting host CallJS vbsAddCode "code" endif // call up the VBScript function // to table // sort by name (ignore case) // reset table display parameters Return
InputScript "excel_processes.txt" // Excel download (CSV table) // build temporary filename using TEMP Set V[tempfile] "&%[TEMP]\guixttemp.&V[today_ymdhms].processes.csv"CopyText fromTable=V[proc] toText="tempexcel" delimiter=";" CopyText fromText="tempexcel" toFile="&V[tempfile]"Start "&[tempfile]"Return
InputScript "active_processes.txt" // computer selected? if not V[computername] Return "W: Please select a computer" -statusline endif // save previous results // call up the VBScript function // create temporary tables of same structure CreateTable V[proc2] include=V[proc] CreateStructure V[procrow1] include=V[proc1] CreateStructure V[procrow2] include=V[proc2] // to table CopyText toTable="V[proc2]" fromText="csvproc" delimiter=";" // fill table proc with active processes Set V[k] 0label compareif V[k<&V[proc2.rowcount]] Set V[k] &V[k] + 1 ReadRow V[procrow2] table=V[proc2] index=&V[k] ReadRow V[procrow1] table=V[proc1] key="&V[procrow2.ProcessId]" // new process, or CPU changed? if not Q[ok] or _ not V[procrow1.UserModeTime=&V[procrow2.UserModeTime]] or _ not V[procrow1.KernelModeTime=&V[procrow2.KernelModeTime]] AppendRow V[procrow2] table=V[proc] endif goto compare endif // sort by name (ignore case) // reset table display parameters Return
|
Components |