Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Creating a hyperv virtual hard disk and machine on Windows 2012R2

Davidka
2014-07-28
2014-07-30
  • Davidka
    Davidka
    2014-07-28

    Hi, All

    I'm trying to read and understand some j-interop code then add functionality to do two things.
    Create a new virtual hard disk on a hyperV system running under windows 2012 R2. I have an implementation that works on 2012R1 but Microsoft has apparently changed the interface for R2. I'm going through our existing code trying to modify it but am running into trouble. Any help, tips, or pointers would be appreciated.

    After the vhd is created, I'm going to create a new virtual machine using it. Hopefully out existing j-interop code will still work, but if not I'll probably post further questions here.

    As always, Thanks in advance.

    David

     
    Last edit: Davidka 2014-07-28
  • Davidka
    Davidka
    2014-07-30

    Further information:
    The Microsoft documentation at http://msdn.microsoft.com/en-us/library/hh850064(v=vs.85).aspx implies an out paramater
    returns a string. I'm curious to see what format this string. (I suspect it is xml), but I'm having trouble writing code to examine it.

    What am I doing wrong?

    Snippet:

    Object[] methodParams = new Object[]{
        new JIString("GetVirtualHardDiskSettingData"),
        new JIVariant(inDispatch),  // contains path of requested disk
        new Integer(0),
        JIVariant.NULL(),
    };
    
    JIVariant result = mgmtSvcDspatch.callMethodA("ExecMethod_", methodParams)[0];
    IJIDispatch resultDispatch = (IJIDispatch) JIObjectFactory.narrowObject(result.getObjectAsComObject());
    
    JIVariant foo = resultDispatch.get("SettingData");  // ok
    int t = foo.getType();
    boolean b = foo.isNull();   // true - why?
    System.out.println("foo type is " + t + " isNull is " + b);
    String sfoo = foo.getObjectAsString2(); // error
    

    Output:
    foo type is 1 isNull is true

     
    Last edit: Davidka 2014-07-30
  • Davidka
    Davidka
    2014-07-30

    Found my error: misspelling in existing disk name. Now I'm looking for a Java example of CreateVirtualHardDisk.