Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting output parameter value set by VBScript (WMI) method in java via JACOB
    text
    copied!<p>Am trying to convert a VBScript to java using JACOB - Java COM bridge library. 'Create' method in VBScript accepts a [out] param in it's method and it sets it upon method execution and i couldn't figure out how to retrieve it back via JACOB.</p> <p>VBScript in question:</p> <pre><code>Function CreateProcess(strComputer, strCommand) Dim objWMIService, objProcess Set objWMIService = GetObject("winmgmts:" &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2") Set objProcess = objWMIService.Get("Win32_Process") errReturn = objProcess.Create (strCommand, Null, Null, intProcessID) Set objWMIService = Nothing Set objProcess = Nothing CreateProcess = intProcessID End Function </code></pre> <p>intProcessID is [out] param set after method execution. (<a href="http://msdn.microsoft.com/en-us/library/aa389388%28v=vs.85%29.aspx" rel="nofollow">Create API contract</a>)</p> <p>Converted java code(incomplete and modified slightly for demonstration):</p> <pre><code>public static void createProcess() { String host = "localhost"; String connectStr = String .format("winmgmts:{impersonationLevel=impersonate}!\\\\%s\\root\\CIMV2", host); ActiveXComponent axWMI = new ActiveXComponent(connectStr); Variant vCollection = axWMI.invoke("get", new Variant("Win32_Process")); Dispatch d = vCollection.toDispatch(); Integer processId = null; int result = Dispatch.call(d, "Create", "notepad.exe", null, null, processId) .toInt(); System.out.println("Result:" + result); // WORKS FINE until here i.e. notepad launches properly, however processId still seems to be null. Following commented code is wrong - doesn't work //Variant v = Dispatch.get(d, "processId"); // even ProcessId doesn't work //int pId = v.getInt(); //System.out.println("process id:" // + pId); // what is the right way to get the process ID set by 'Create' method? } </code></pre> <p>Would be great if you could provide some pointers or relevant code. Ask me more if needed. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload