我正在尝试使用j-interop来实现下面的wmic命令。
wmic /NODE:192.168.0.195 /USER:Test /PASSWORD:password123 process call create "calc.exe"
在我的方法中,我的代码是这样写的。我还有另外两个方法,这两个方法创建会话并连接到WMI服务,以便处理该部分。
public void wmiExecute() throws JIException {
// Obtain Win32_Process and narrow it as IJIDispatch
Object[] params = new Object[] {
new JIString("Win32_Process"),
new Integer(0),
JIVariant.OPTIONAL_PARAM()
};
JIVariant[] servicesSet = this._wbemServices.callMethodA("InstancesOf", params);
IJIDispatch wbemObjectSet = (IJIDispatch) JIObjectFactory.narrowObject(servicesSet[0].getObjectAsComObject());
params = new Object[] {
"calc.exe",
JIVariant.OPTIONAL_PARAM(),
JIVariant.OPTIONAL_PARAM(),
new Integer(0),
};
wbemObjectSet.callMethodA("Create", params);
}
我不断地得到一个例外
Caught Throwable: org.jinterop.dcom.common.JIException: Unknown name. [0x80020006]
org.jinterop.dcom.common.JIException: Unknown name. [0x80020006]
你知道会出什么问题吗?提前感谢!
发布于 2013-02-27 00:31:19
这就是解决方案。
您不应该使用InstanceOf来获取Win32_Process,因为您将只获取当前正在运行的进程的列表。相反,您应该使用"Get“来获取默认的Win32_Process。
public void wmiExecute() throws JIException {
// Obtain Win32_Process and narrow it as IJIDispatch
Object[] params = new Object[] {
new JIString("Win32_Process"),
JIVariant.OPTIONAL_PARAM(),
JIVariant.OPTIONAL_PARAM()
};
// Obtain the default Win32_Process
JIVariant[] service = this._wbemServices.callMethodA("Get", params);
// Convert it to a IJIDispatch object
IJIDispatch wbemObject = (IJIDispatch) JIObjectFactory.narrowObject(service[0].getObjectAsComObject());
// Create input params
Object[] paramsCalc = new Object[] {
new JIString("calc.exe"),
JIVariant.OPTIONAL_PARAM(),
JIVariant.OPTIONAL_PARAM()
};
// Create the calculator process
JIVariant[] results = wbemObject.callMethodA("Create", paramsCalc);
}
https://stackoverflow.com/questions/14991736
复制相似问题