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

  • 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.


    Last edit: Davidka 2014-07-28
  • Davidka

    Davidka - 2014-07-30

    Further information:
    The Microsoft documentation at 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?


    Object[] methodParams = new Object[]{
    new JIString("GetVirtualHardDiskSettingData"),
    new JIVariant(inDispatch), // contains path of requested disk
    new Integer(0),

    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

    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.

    • Eric Song

      Eric Song - 2016-07-05

      Hi, David. I am recently trying to create virtual hard disk via Java for our Hyper-V project. Can you give some suggestions about how to do it?


Log in to post a comment.