Overview

This library implements a .NET layer over the Hyper-V API as exposed through WMI. The library is written in C# and is not currently CLS Compliant.

System Requiremens

Windows Server 2008 R2

Example: Create VHDs

        using (var ims = new ImageManagementService())
        {
            ims.CreateFixedVirtualHardDisk(pathFixedSizeDisk, testVhdSize);
            Debug.Assert(File.Exists(pathFixedSizeDisk));
            Console.WriteLine("Fixed VHD created: " + pathFixedSizeDisk);

            ims.CreateDynamicVirtualHardDisk(pathDynamicDisk, testVhdSize);
            Debug.Assert(File.Exists(pathDynamicDisk));
            Console.WriteLine("Dynamic VHD created: " + pathDynamicDisk);

            ims.CreateDifferencingVirtualHardDisk(pathDifferencingDisk, pathDynamicDisk);
            Debug.Assert(File.Exists(pathDifferencingDisk));
            Console.WriteLine("Differencing VHD created: " + pathDifferencingDisk);
        }

Example: Create Snapshot

            // Create Snapshot

            string nameOfTargetVirtualMachineToSnapshot = "Hyper-V Library Testing";

            using (var vsms = new VirtualSystemManagementService())
            {
                string snapshotName = null; // when not null, means target VM was found and snapshot was created

                Console.WriteLine("Virtual Machines:");
                foreach (string vmName in vsms.GetVmList())
                {
                    Console.Write("VM: " + vmName);

                    if (vmName == nameOfTargetVirtualMachineToSnapshot)
                    {
                        var result = vsms.CreateVirtualSystemSnapshot(vmName);
                        snapshotName = result.Name;
                        Console.Write(" >>> SNAP! >>> '" + result.Name + "'");
                    }
                    Console.WriteLine();
                }
                
                if (string.IsNullOrEmpty(snapshotName))
                {
                    Console.WriteLine(string.Format("Snapshot Target Not Found ('{0}'.)", nameOfTargetVirtualMachineToSnapshot));
                }
            }

Last edited Oct 24, 2010 at 9:58 AM by AntonDelsink, version 5

Comments

No comments yet.