问题描述
我在调用方法时遇到问题(通过j-interop在Msvm_ImageManagementService上调用GetVirtualHardDiskState。 该方法将共享的"路径"(群集共享卷或SMB)作为输入。 它输出的内容类似于共享使用的存储金额
。
$
当我调用传递CSV的方法时,它的工作方式如下:
$
" C:\ \ClusterStorage \\Volume2 \\JBoss-AS-73 \\\disk-0_34ED4EE3-A200-40DC-862F-A036387FB8C3.avhdx"
当我通过以下SMB路径时,它不起作用:
" \\\\smb01.corp.vmturbo.com \\smbshare04 \\ SMB_C_TEST \\SMB_C_TEST_disk_1.vhdx"
$
我附上了我使用的代码。 我使用j-Interop_3_0_0.tar库。
如果您对我的错误有任何疑问,请与我们联系。
$
问候
Pankaj Batra
$
-----
$
b代码
$ b
import java.util.HashSet;
import java.util.logging.Level;
import org.jinterop.dcom.common.JIException;
$
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom .core.IJIComObject;
$
import org.jinterop.dcom.core.JIArray;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JIProgId;
$
import org.jinterop.dcom.core.JISession;
$
import org.jinterop.dcom.core.JIString;
import org.jinterop.dcom.core.JIVariant;
import org.jinterop.dcom.impls.JIObjectFactory;
import org.jinterop .dcom.impls.automation.IJIDispatch;
import org.jinterop.dcom.i mpls.automation.IJIEnumVariant;
$
公共类getClassInfo {
  public static IJIDispatch dispatcher(JIVariant var)抛出JIException {
      if(var!= null)
          return dispatcher(var.getObjectAsComObject());
     否则{
         返回null;
      }¥b $ b   }
  public static IJIDispatch dispatcher(IJIComObject comObj)抛出JIException {
      return(IJIDispatch)JIObjectFactory.narrowObject(comObj);
  }
  public static int queryMethodNumber(String methodName,JIVariant variant)抛出JIException {
      IJIDispatch dispatch =(IJIDispatch)JIObjectFactory.narrowObject(变体
.getObjectAsComObject());
      JIVariant jiCount = dispatch.get(" Count");
      int count = jiCount.getObjectAsInt();
      JIVariant variant2 = dispatch.get(" _NewEnum");
      int methodNum = -1;
      IJIEnumVariant enumVARIANT2 =(IJIEnumVariant)JIObjectFactory.narrowObject(variant2
.getObjectAsComObject()。queryInterface( IJIEnumVariant.IID));
&NBSP; &NBSP; &NBSP; for(int i = 0; i< count; i ++){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Object [] valueArray = enumVARIANT2.next(1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIArray array =(JIArray)valueArray [0];
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Object [] arrayObj =(Object [])array.getArrayInstance();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch methodDispatch =(IJIDispatch)JIObjectFactory
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .narrowObject(((JIVariant)arrayObj [0])。getObjectAsComObject());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(methodDispatch.get(" Name")。getObjectAsString2()。equals(methodName)){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; methodNum = i;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; return methodNum;
&NBSP; }
&NBSP; public static IJIComObject enumGet(IJIEnumVariant enumerator,int i)抛出JIException {
&NBSP; &NBSP; &NBSP; enumerator.reset();
&NBSP; &NBSP; &NBSP; enumerator.skip(i);
&NBSP; &NBSP; &NBSP; Object [] values = enumerator.next(1);
&NBSP; &NBSP; &NBSP; JIArray数组=(JIArray)值[0];
&NBSP; &NBSP; &NBSP; Object [] arrayObj =(Object [])array.getArrayInstance();
&NBSP; &NBSP; &NBSP; IJIComObject com =((JIVariant)arrayObj [0])。getObjectAsComObject();
&NBSP; &NBSP; &NBSP;返回com;
&NBSP; }
&NBSP; public static IJIEnumVariant枚举器(IJIDispatch dispatch)抛出JIException {
&NBSP; &NBSP; &NBSP; JIVariant variant = dispatch.get(" _NewEnum");
&NBSP; &NBSP; &NBSP; IJIComObject coEnum = variant.getObjectAsComObject();
&NBSP; &NBSP; &NBSP; coEnum = coEnum.queryInterface(IJIEnumVariant.IID);
&NBSP; &NBSP; &NBSP; IJIEnumVariant enumerator =(IJIEnumVariant)JIObjectFactory.narrowObject(coEnum);
&NBSP; &NBSP; &NBSP;返回普查员;
&NBSP; }
&NBSP; public static String VariantToString(JIVariant var)抛出JIException {
&NBSP; &NBSP; &NBSP;字符串值= null;
&NBSP; &NBSP; &NBSP; switch(var.getType()){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例JIVariant.VT_BSTR:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; value = var.getObjectAsString()。getString();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例JIVariant.VT_BOOL:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; value = String.valueOf(var.getObjectAsBoolean());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例8204:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例JIVariant.VT_ARRAY:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant [] newValue =(JIVariant [])var.getObjectAsArray()。getArrayInstance();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;的HashSet<字符串> h = new HashSet< String>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(JIVariant s:newValue){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; h.add(VariantToString(s));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; value = h.toString();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例JIVariant.VT_I4:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例JIVariant.VT_INT:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; value = String.valueOf(var.getObjectAsInt());
&NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP;返回值;
&NBSP; }
&NBSP; public static void main(String [] args){
&NBSP; &NBSP; &NBSP; final int DEFAULT_TIMEOUT = 30000;
&NBSP; &NBSP; &NBSP; // final String WMI_DEFAULT_NAMESPACE =" root \\CIMV2";
&NBSP; &NBSP; &NBSP; // final String APP_QUERY =" Select * from Win32_PerfFormattedData_PerfProc_Process";
&NBSP; &NBSP; &NBSP; JIComServer comStub = null;
&NBSP; &NBSP; &NBSP; IJIDispatch dispatch = null;
&NBSP; &NBSP; &NBSP; IJIComObject comObject = null;
&NBSP; &NBSP; &NBSP; JISession session = null;
&NBSP; &NBSP; &NBSP; if(args.length!= 5){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; System.out.println("请输入所有参数:IP用户名密码命名空间类");
&NBSP; &NBSP; &NBSP; }其他{
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;试试{
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String namespace = args [3];
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String classInfo = args [4];
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String query =" Select * From" + classInfo;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JISystem.getLogger()。setLevel(Level.FINEST);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JISystem.setInBuiltLogHandler(false);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JISystem.setAutoRegisteration(false);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String domain ="" ;;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String username = args [1];
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(args [1] .indexOf(" \\")> 0){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; domain = username.substring(0,username.indexOf(" \\"));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; username = username.substring(username.indexOf(" \\")+ 2,username.length());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; System.out.println(" Domain" + domain +" username" + username +" args2" + args [2]);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; session = JISession.createSession(domain,username,args [2]);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; session.useSessionSecurity(true);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; session.useNTLMv2(true);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; session.setGlobalSocketTimeout(DEFAULT_TIMEOUT);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; comStub = new JIComServer(JIProgId.valueOf(" WbemScripting.SWbemLocator"),args [0],session);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIComObject unknown = comStub.createInstance();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; comObject = unknown.queryInterface(" 76A6415B-CB41-11d1-8B02-00600806D9B6"); // ISWbemLocator
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; dispatch =(IJIDispatch)JIObjectFactory.narrowObject(comObject.queryInterface(IJIDispatch.IID));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant结果[] = dispatch.callMethodA(" ConnectServer",new Object [] {new JIString(args [0]),
new JIString(namespace),
JIVariant。 OPTIONAL_PARAM(),&
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant.OPTIONAL_PARAM(),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 新JIString(" MS_409"),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant.OPTIONAL_PARAM(),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; new Integer(0),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant.OPTIONAL_PARAM()});
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch wbemServices_dispatch =(IJIDispatch)JIObjectFactory.narrowObject((results [0])。getObjectAsComObject());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; results = wbemServices_dispatch.callMethodA(" ExecQuery",new Object [] {new JIString(query),JIVariant.OPTIONAL_PARAM(),JIVariant.OPTIONAL_PARAM()});
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch wbemObjectSet_dispatch =(IJIDispatch)JIObjectFactory.narrowObject((results [0])。getObjectAsComObject());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant variant = wbemObjectSet_dispatch.get(" _NewEnum");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIComObject object2 = variant.getObjectAsComObject();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIEnumVariant enumVARIANT =(IJIEnumVariant)JIObjectFactory.narrowObject(object2.queryInterface(IJIEnumVariant.IID));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant Count = wbemObjectSet_dispatch.get(" Count");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; int count = Count.getObjectAsInt();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; System.out.println("实例总数为:" + count);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int i = 0; i< count; i ++)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Object [] values = enumVARIANT.next(1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIArray数组=(JIArray)值[0];
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Object [] arrayObj =(Object [])array.getArrayInstance();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch wbemObject_dispatch =(IJIDispatch)JIObjectFactory.narrowObject(((JIVariant)arrayObj [0])。getObjectAsComObject());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String mof = null;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant variant2 =(wbemObject_dispatch.callMethodA(" GetObjectText_",new Object [] {new Integer(1)}))[0];
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; mof = variant2.getObjectAsString()。getString();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; System.out.println(mof);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(!classInfo.equals(" Msvm_ImageManagementService"))){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;继续;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //现在进行路径查询。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant variant3 = wbemObject_dispatch.get(" Methods_");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; int mNumber = -1;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String method =" GetVirtualHardDiskState";
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String output =" State"; $
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; mNumber = queryMethodNumber(method,variant3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch methodsDispatch = dispatcher(variant3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIEnumVariant methodsEnumerator = enumerator(methodsDispatch);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIComObject getVirtualHardDiskInfoComObject = enumGet(methodsEnumerator,mNumber);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch getVirtualHardDiskInfoDispatch = dispatcher(getVirtualHardDiskInfoComObject);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant variant4 = getVirtualHardDiskInfoDispatch.get(" InParameters");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch inDispatch = dispatcher(variant4);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // SMB在hp-dl592上为
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // String path =" \\\\smb01.corp.vmturbo.com \\smbshare04 \\SMB_C_TEST \\SMB_C_TEST_disk_1.vhdx" ;;
  ; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // 10.10.64.192 corp\\pankaj.batra pwd root / virtualization / v2 Msvm_ImageManagementService
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //在592上$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // String path =" - ? - UNC-smb01.corp.vmturbo.com-smbshare01-vmt-590-5-vmturbo64-opsmgr-4_5.vhd" ;;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //在591¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // String path =" - ? - UNC-smb01-smbshare01-PankajVM-Virtual Hard Disks-PankajVM.vhdx";
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String path =" - ? - UNC-smb01-smbshare01-PankajVM-Virtual Hard Disks-PankajVM.vhdx";
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; \\\\ 01 = \\ smbshare01 \ PankajVM \ Virtual Hard Disks \ PankajVM.vhdx
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // CSV位于hp-dl590上
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // 10.10.64.190 corp\\pankaj.batra pwd root / virtualization / v2 Msvm_ImageManagementService
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // String path =" C:\\ClusterStorage \\Volume2 \\JBoss-AS-73 \\disk-0_34ED4EE3-A200-40DC-862F-A036387FB8C3.avhdx" ;;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; inDispatch.put(" Path",new JIVariant(new JIString(path)));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Object [] methodParams = new Object [] {new JIString(method),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;新的JIVariant(inDispatch),$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;新整数(0),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant.NULL(),};
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //执行方法。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant [] virtualHardDiskInfo = wbemObject_dispatch.callMethodA(" ExecMethod_",
methodParams);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant outParamsVar = virtualHardDiskInfo [0];
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IJIDispatch outParamsDisp = dispatcher(outParamsVar);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JIVariant diskInfoVars = null;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; diskInfoVars = outParamsDisp.get(output);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;字符串结果= null;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; result = VariantToString(diskInfoVars);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; System.out.println("查询光盘查询的输出是:"+结果);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; } catch(例外e){
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; e.printStackTrace();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; }
}
$
Hi,
I am having an issue invoking a method (called GetVirtualHardDiskState) on Msvm_ImageManagementService via j-interop. The method takes as input the 'path' of a share (either Cluster Share Volume or SMB). It outputs things like the storage amount used by the share.
It works when I invoke the method passing in a CSV with a path like:
"C:\\ClusterStorage\\Volume2\\JBoss-AS-73\\disk-0_34ED4EE3-A200-40DC-862F-A036387FB8C3.avhdx"
It does not work when I pass in an SMB path like:
"\\\\smb01.corp.vmturbo.com\\smbshare04\\SMB_C_TEST\\SMB_C_TEST_disk_1.vhdx"
I'm attaching the code that I use. I use j-Interop_3_0_0.tar libraries.
Please let me know if you have any ideas on what I may be doing wrong.
Regards
Pankaj Batra
-----
CODE
import java.util.HashSet;
import java.util.logging.Level;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIArray;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JIProgId;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.core.JIString;
import org.jinterop.dcom.core.JIVariant;
import org.jinterop.dcom.impls.JIObjectFactory;
import org.jinterop.dcom.impls.automation.IJIDispatch;
import org.jinterop.dcom.impls.automation.IJIEnumVariant;
public class getClassInfo {
public static IJIDispatch dispatcher(JIVariant var) throws JIException {
if (var != null)
return dispatcher(var.getObjectAsComObject());
else {
return null;
}
}
public static IJIDispatch dispatcher(IJIComObject comObj) throws JIException {
return (IJIDispatch)JIObjectFactory.narrowObject(comObj);
}
public static int queryMethodNumber(String methodName, JIVariant variant) throws JIException {
IJIDispatch dispatch = (IJIDispatch)JIObjectFactory.narrowObject(variant
.getObjectAsComObject());
JIVariant jiCount = dispatch.get("Count");
int count = jiCount.getObjectAsInt();
JIVariant variant2 = dispatch.get("_NewEnum");
int methodNum = -1;
IJIEnumVariant enumVARIANT2 = (IJIEnumVariant)JIObjectFactory.narrowObject(variant2
.getObjectAsComObject().queryInterface(IJIEnumVariant.IID));
for (int i = 0; i < count; i++) {
Object[] valueArray = enumVARIANT2.next(1);
JIArray array = (JIArray)valueArray[0];
Object[] arrayObj = (Object[])array.getArrayInstance();
IJIDispatch methodDispatch = (IJIDispatch)JIObjectFactory
.narrowObject(((JIVariant)arrayObj[0]).getObjectAsComObject());
if (methodDispatch.get("Name").getObjectAsString2().equals(methodName)) {
methodNum = i;
break;
}
}
return methodNum;
}
public static IJIComObject enumGet(IJIEnumVariant enumerator, int i) throws JIException {
enumerator.reset();
enumerator.skip(i);
Object[] values = enumerator.next(1);
JIArray array = (JIArray)values[0];
Object[] arrayObj = (Object[])array.getArrayInstance();
IJIComObject com = ((JIVariant)arrayObj[0]).getObjectAsComObject();
return com;
}
public static IJIEnumVariant enumerator(IJIDispatch dispatch) throws JIException {
JIVariant variant = dispatch.get("_NewEnum");
IJIComObject coEnum = variant.getObjectAsComObject();
coEnum = coEnum.queryInterface(IJIEnumVariant.IID);
IJIEnumVariant enumerator = (IJIEnumVariant)JIObjectFactory.narrowObject(coEnum);
return enumerator;
}
public static String VariantToString(JIVariant var) throws JIException {
String value = null;
switch (var.getType()) {
case JIVariant.VT_BSTR:
value = var.getObjectAsString().getString();
break;
case JIVariant.VT_BOOL:
value = String.valueOf(var.getObjectAsBoolean());
break;
case 8204:
case JIVariant.VT_ARRAY:
JIVariant[] newValue = (JIVariant[])var.getObjectAsArray().getArrayInstance();
HashSet<String> h = new HashSet<String>();
for (JIVariant s : newValue) {
h.add(VariantToString(s));
}
value = h.toString();
break;
case JIVariant.VT_I4:
case JIVariant.VT_INT:
value = String.valueOf(var.getObjectAsInt());
}
return value;
}
public static void main(String[] args) {
final int DEFAULT_TIMEOUT = 30000;
// final String WMI_DEFAULT_NAMESPACE = "root\\CIMV2";
// final String APP_QUERY = "Select * from Win32_PerfFormattedData_PerfProc_Process";
JIComServer comStub = null;
IJIDispatch dispatch = null;
IJIComObject comObject = null;
JISession session = null;
if (args.length != 5) {
System.out.println("Please input all the arguments as: IP Username Password Namespace class");
} else {
try {
String namespace = args[3];
String classInfo = args [4];
String query = "Select * From " + classInfo;
JISystem.getLogger().setLevel(Level.FINEST);
JISystem.setInBuiltLogHandler(false);
JISystem.setAutoRegisteration(false);
String domain = "";
String username = args[1];
if (args[1].indexOf("\\") > 0) {
domain = username.substring(0, username.indexOf("\\"));
username = username.substring(username.indexOf("\\") + 2, username.length());
}
System.out.println("Domain " + domain + " username " + username + " args2 " + args[2]);
session = JISession.createSession(domain,username,args[2]);
session.useSessionSecurity(true);
session.useNTLMv2(true);
session.setGlobalSocketTimeout(DEFAULT_TIMEOUT);
comStub = new JIComServer(JIProgId.valueOf("WbemScripting.SWbemLocator"),args[0],session);
IJIComObject unknown = comStub.createInstance();
comObject = unknown.queryInterface("76A6415B-CB41-11d1-8B02-00600806D9B6");//ISWbemLocator
dispatch = (IJIDispatch)JIObjectFactory.narrowObject(comObject.queryInterface(IJIDispatch.IID));
JIVariant results[] = dispatch.callMethodA( "ConnectServer", new Object[] { new JIString(args[0]),
new JIString( namespace ),
JIVariant.OPTIONAL_PARAM(),
JIVariant.OPTIONAL_PARAM(),
new JIString("MS_409"),
JIVariant.OPTIONAL_PARAM(),
new Integer( 0 ),
JIVariant.OPTIONAL_PARAM() } );
IJIDispatch wbemServices_dispatch = (IJIDispatch)JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
results = wbemServices_dispatch.callMethodA("ExecQuery", new Object[]{new JIString(query), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM()});
IJIDispatch wbemObjectSet_dispatch = (IJIDispatch)JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
JIVariant variant = wbemObjectSet_dispatch.get("_NewEnum");
IJIComObject object2 = variant.getObjectAsComObject();
IJIEnumVariant enumVARIANT = (IJIEnumVariant)JIObjectFactory.narrowObject(object2.queryInterface(IJIEnumVariant.IID));
JIVariant Count = wbemObjectSet_dispatch.get("Count");
int count = Count.getObjectAsInt();
System.out.println("The total number of instances are: " + count);
for (int i = 0; i < count; i++)
{
Object[] values = enumVARIANT.next(1);
JIArray array = (JIArray)values[0];
Object[] arrayObj = (Object[])array.getArrayInstance();
IJIDispatch wbemObject_dispatch = (IJIDispatch)JIObjectFactory.narrowObject(((JIVariant)arrayObj[0]).getObjectAsComObject());
String mof = null;
JIVariant variant2 = (wbemObject_dispatch.callMethodA("GetObjectText_",new Object[]{new Integer(1)}))[0];
mof = variant2.getObjectAsString().getString();
System.out.println(mof);
if (!classInfo.equals("Msvm_ImageManagementService")) {
continue;
}
// Now make the path query.
JIVariant variant3 = wbemObject_dispatch.get("Methods_");
int mNumber = -1;
String method = "GetVirtualHardDiskState";
String output = "State";
mNumber = queryMethodNumber(method, variant3);
IJIDispatch methodsDispatch = dispatcher(variant3);
IJIEnumVariant methodsEnumerator = enumerator(methodsDispatch);
IJIComObject getVirtualHardDiskInfoComObject = enumGet(methodsEnumerator, mNumber);
IJIDispatch getVirtualHardDiskInfoDispatch = dispatcher(getVirtualHardDiskInfoComObject);
JIVariant variant4 = getVirtualHardDiskInfoDispatch.get("InParameters");
IJIDispatch inDispatch = dispatcher(variant4);
// The SMB is on hp-dl592
// String path = "\\\\smb01.corp.vmturbo.com\\smbshare04\\SMB_C_TEST\\SMB_C_TEST_disk_1.vhdx";
// 10.10.64.192 corp\\pankaj.batra pwd root/virtualization/v2 Msvm_ImageManagementService
// On 592
// String path = "--?-UNC-smb01.corp.vmturbo.com-smbshare01-vmt-590-5-vmturbo64-opsmgr-4_5.vhd";
// On 591
// String path = "--?-UNC-smb01-smbshare01-PankajVM-Virtual Hard Disks-PankajVM.vhdx";
String path = "--?-UNC-smb01-smbshare01-PankajVM-Virtual Hard Disks-PankajVM.vhdx";
// \\smb01\smbshare01\PankajVM\Virtual Hard Disks\PankajVM.vhdx
// The CSV is on hp-dl590
// 10.10.64.190 corp\\pankaj.batra pwd root/virtualization/v2 Msvm_ImageManagementService
// String path = "C:\\ClusterStorage\\Volume2\\JBoss-AS-73\\disk-0_34ED4EE3-A200-40DC-862F-A036387FB8C3.avhdx";
inDispatch.put("Path", new JIVariant(new JIString(path)));
Object[] methodParams = new Object[] {new JIString(method),
new JIVariant(inDispatch),
new Integer(0),
JIVariant.NULL(),};
// Execute the method.
JIVariant[] virtualHardDiskInfo = wbemObject_dispatch.callMethodA("ExecMethod_",
methodParams);
JIVariant outParamsVar = virtualHardDiskInfo[0];
IJIDispatch outParamsDisp = dispatcher(outParamsVar);
JIVariant diskInfoVars = null;
diskInfoVars = outParamsDisp.get(output);
String result = null;
result = VariantToString(diskInfoVars);
System.out.println("Query output for disc query is :" + result);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
这篇关于在SMB互通中传递SMB路径作为输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!