Share via

Hyper-V generation 2 virtual machine sample

This sample demonstrates how to use the Hyper-V WMI APIs to manage generation 2 virtual machines.

Note The Windows-classic-samples repo contains a variety of code samples that exercise the various programming models, platforms, features, and components available in Windows and/or Windows Server. This repo provides a Visual Studio solution (SLN) file for each sample, along with the source files, assets, resources, and metadata needed to compile and run the sample. For more info about the programming models, platforms, languages, and APIs demonstrated in these samples, check out the documentation on the Windows Dev Center. This sample is provided as-is in order to indicate or demonstrate the functionality of the programming models and feature APIs for Windows and/or Windows Server. This sample was created for Windows 8.1 and/or Windows Server 2012 R2 using Visual Studio 2013, but in many cases it will run unaltered using later versions. This sample was created for Windows 8.1 and/or Windows Server 2012 R2 using Visual Studio 2013, but in many cases it will run unaltered using later versions. Please provide feedback on this sample!

To get a copy of Visual Studio, go to Visual Studio Downloads.

Operating system requirements

Client

Windows 8.1

Server

Windows Server 2012 R2

Build the sample

Building the C# version of the sample

  1. Start Visual Studio and select File > Open > Project/Solution.

  2. Go to the directory named for the sample, and select the Microsoft Visual Studio Solution (.sln) file titled gen2vm.sln from Visual Studio.

  3. Press F7 or use Build > Build Solution to build the sample.

Run the sample

Running the C# version of the sample

Note This sample must be run as an administrator.

This sample is written in C# using the Hyper-V WMI APIs, and requires some experience with WMI programming.

This sample can be run in several different modes.

Hyper-V WMI provider (V2)

Using the Hyper-V WMI provider