none
HyperV - How to copy a text file from host to virtual machine

    Question

  • Hi,

     How to copy a text file from Hyper V host machine to a Virtual machine using C# WMI API for Hyper V?

    Regards,

    - Hari

    Wednesday, November 16, 2011 4:10 AM

Answers

  • Hi Harry,

    I think this is not possible. Data flows from the parent partition to the child partition via VMBus (clearly in RAM) and/or through the hypervisor. You can use hypervisor API for Hyper-V but the API is WMI!. Informations about API say you can use it for create/manage/monitor/configure actions. There's nothing about data transfer.

    You should go under the "WMI layer" itself but I think it is too deep and there is no public informations how to do it...


    Jan Marek MCT | MCITP | MCTS
    Wednesday, November 16, 2011 11:03 AM
  • Jan has it!

    WMI does not support data transfer.

    You can pass data in to the machine using WinRM (not really a file, but the contents of a file could be).  It is not straightforward, but passing in a string and getting a responce back can be done.  (only the first time is difficult).

    Your other option is to use the physical layer somehow calling it through WMI - take your file, wrap it in a virtual floppy or an ISO and mount it to the VM.  Then call the WMI of the VM OS and read the file and do something with it.

    and so on.


    Brian Ehlert (hopefully you have found this useful) http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    • Marked as answer by .Net-Hari Thursday, November 17, 2011 3:59 AM
    Wednesday, November 16, 2011 4:17 PM
    Moderator

All replies

  • Hi,

     

    Do you have to use C# WMI API? If not, you can refer to:

     

    Hyper-V How To: Share Resources

    http://blogs.technet.com/b/tonyso/archive/2008/09/09/hyper-v-how-to-share-resources.aspx

     

    Hyper-V: Exchanging files between Parent and Child Partitions

    http://www.ditii.com/2008/09/17/hyper-v-exchanging-files-between-parent-and-child-partitions/

     

    Important Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

     

     

    Best Regards,

    Vincent Hu

     

     

    • Marked as answer by .Net-Hari Wednesday, November 16, 2011 9:07 AM
    • Unmarked as answer by .Net-Hari Wednesday, November 16, 2011 9:07 AM
    Wednesday, November 16, 2011 8:47 AM
    Moderator
  • Hi Vincent,

    Thanks for the replay.

    Yes, I need to use "C# WMI API for Hyper V".

    Because this will happen on the fly. My C# code will transfer the file from host to VM.

    Is this possible?

    Regards,

    - Hari

    Wednesday, November 16, 2011 9:07 AM
  • Hi Harry,

    I think this is not possible. Data flows from the parent partition to the child partition via VMBus (clearly in RAM) and/or through the hypervisor. You can use hypervisor API for Hyper-V but the API is WMI!. Informations about API say you can use it for create/manage/monitor/configure actions. There's nothing about data transfer.

    You should go under the "WMI layer" itself but I think it is too deep and there is no public informations how to do it...


    Jan Marek MCT | MCITP | MCTS
    Wednesday, November 16, 2011 11:03 AM
  • Thank you Jan for the replay.

     

    What do you mean by "Wmi Layer" here ?

     

    Regards,

    Hari

    Wednesday, November 16, 2011 11:08 AM
  • I mean the WMI namespace \\root\virtualization. and WMI classes, calls and so on... http://msdn.microsoft.com/en-us/library/cc136992(VS.85).aspx
    Jan Marek MCT | MCITP | MCTS
    Wednesday, November 16, 2011 11:21 AM
  • Thank you Jan.
    Wednesday, November 16, 2011 11:42 AM
  • you're welcome man! could you pls mark my reply as an answer? i would really appreciate that... thank you...
    Jan Marek MCT | MCITP | MCTS
    Wednesday, November 16, 2011 4:12 PM
  • Jan has it!

    WMI does not support data transfer.

    You can pass data in to the machine using WinRM (not really a file, but the contents of a file could be).  It is not straightforward, but passing in a string and getting a responce back can be done.  (only the first time is difficult).

    Your other option is to use the physical layer somehow calling it through WMI - take your file, wrap it in a virtual floppy or an ISO and mount it to the VM.  Then call the WMI of the VM OS and read the file and do something with it.

    and so on.


    Brian Ehlert (hopefully you have found this useful) http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    • Marked as answer by .Net-Hari Thursday, November 17, 2011 3:59 AM
    Wednesday, November 16, 2011 4:17 PM
    Moderator
  • Thanks Brian,

    according to your reply - it is really interesting idea to get the data into the VM via the floppy or iso! The opposite way is possible only using the floppy because it is writable... what do you think?


    Jan Marek MCT | MCITP | MCTS
    Wednesday, November 16, 2011 4:42 PM
  • Actaully, there are lots of management systems that use the virtual floppy trick.  (SCVMM comes to mind).

    on the client side you generate the floppy, add your file, copy it out to the hyper-v server using BITS, mount it to the VM, then somehow do the rest from within the OS of the VM.

    Witht he Citrix Kensho project a few years back we used a bootable ISO image.  It contained what we needed and scripts.  Attach to the VM, set the boot order, boot, the ISO takes over and shuts down when done, remove the ISO and detach.

    There are lots of ways to handle this.

    And I didn't even mention directly mounting the VHD of the VM and copiny in your file directly (only if the VM is off) - but again, not with WMI - WinRM.


    Brian Ehlert (hopefully you have found this useful) http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    Wednesday, November 16, 2011 5:29 PM
    Moderator
  • Thanks Jan and Brian for your suggessions.
    Thursday, November 17, 2011 3:59 AM