通过JACOB获取java中VBScript(WMI)方法设置的输出参数值
我试图使用JACOB - Java COM桥库将VBScript转换为java。
VBScript中的'Create'方法在它的方法中接受[out] param,它在方法执行时设置它,我无法弄清楚如何通过JACOB检索它。
有问题的VBScript:
Function CreateProcess(strComputer, strCommand)
Dim objWMIService, objProcess
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create (strCommand, Null, Null, intProcessID)
Set objWMIService = Nothing
Set objProcess = Nothing
CreateProcess = intProcessID
End Function
方法执行后intProcessID是[out] param set。 (创建API合同)
转换的java代码(不完整和稍微修改以用于演示):
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?
}
如果您能提供一些指针或相关代码,那将会很棒。如果需要,请向我询问。提前致谢。
没有找到相关结果
已邀请:
1 个回复
俯乡骚钵皆
同
应该解决问题。然后,您应该在processId变体中具有notepad.exe进程的进程ID,并且可以通过它获取它