Поделиться через


Hyper-V Manager

Wrote this tool when I was setting up my laptop to run Hyper-V.  I didn't want to have to open the Hyper-V manager and have a window running all the time, and was planning on using Remote Desktop Client to connect to the VM's so I could map drives and copy/paste in teh VMs.  The idea was to have something that sits in the System Tray that allows you to Start, Stop, Save State, and Pause the VMs running on the box.

I did some looking around as I had no idea how to manage Hyper-V programmatically.  Luckily, some blogs were around that indicated WMI would be the way to go

With that, I dug in.  The files are attached and feel free to do with them what you want.  Zip contains 2 folders.  Compiled EXE is in the Hyper-VManager folder.  The Visual Studio 2008 project is in the Hyper-VManager_Source folder.

When you launch the app, you will get a UAC prompt.  The app needs to run with admin access to get to Hyper-V objects.  You get the same prompts opening the Hyper-V MMC.  Here's a quick break down of the app and what it does.  It currently manages a single machine.  You can manage a remote machine by changing the .config file entry.  Change \\.\ to \\MachineName\ and you should be good to go (considering you have permissions to the remote machine).  You could extend the app to manage multiple machines, but would need to tweak the code to handle building out the appropriate menus.  Shouldn't be much code, but considering I'm not going to be using it, decided not to do the work :-)

When you launch the app, it displays a Hyper-V icon in the System Tray:

System Tray Icon

Right-click the icon and you get a list of the Virtual Machines on that machine with the current state of the machine.  In this case the VM is Running:

List of VMs

Select a machine and you get four options:  Start, Stop, Save State, and Pause.  These get enabled/disabled depending on the current state.  Since the VM is currently running, the option to Start is disabled.

Action Menu

Changing the state of the VM results in a balloon notification to let you know the machine is changing.  You get a second notification once the state change has completed.  You can change multiple machines, and will get the various balloons for the machines. For example, clicking Save State shows the following notification:

Balloon Status Notification Change

Now that the VM is in a saved state, the menu updates to show the current status and the other menu options are disabled.

Options Disabled Based on Status

Something I found while putting the notification piece together is that if you don't move the mouse or interact with the machine, the initial balloon will not go away after the InitialDuration property value.  Thought it was odd, but looks like it's by design as the idea is if you're not interacting with the machine, you may miss the notification, so they display it until you start working on the box again.

That's pretty much it.  Good luck!

Hyper-VManager_Files.zip

Comments

  • Anonymous
    June 16, 2010
    this is amazing small tool - very nice. I don't need to run each time the big Hyper-V Manager to control VM's daily.

  • Anonymous
    November 09, 2010
    Nice little tool.  I have to start and stop test/sandbox machines all day. Nice to avoid the huge, slow Microsoft HV manager!

  • Anonymous
    May 23, 2011
    Not working in Windows 7 profesional. :-(

  • Anonymous
    July 13, 2011
    Looks like the problem with the application running on Windows 7 is that the tool accesses a WMI class that is installed by Hyper-V.  Windows 7 cannot run Hyper-V, so the WMI class is missing. The config file points to the local machine's virtualization class by default:   .rootvirtualizationMsvm_ComputerSystem The virtualization objects are installed by Hyper-V.  In order to avoid the error, update the .config file to point to your Hyper-V server.   Change :   .virtualization To :  \serverNamevirtualization Save the config file, and relaunch the application.  As long as the firewall and permissions are open enough for you to remotely connecto to WMI on the remote server it should work.  You can also test by running the following in PowerShell: Get-WMIObject Msvm_ComputerSystem -Computer ServerName

  • Anonymous
    January 04, 2013
    I love this tool but it misses something that the VMware one has. It changes colour when some vs none are running.  If it running in the system tray then it easily explains at a glance the cause of your computer going slowly.  You see you've left some VM(s) running. :)

  • Anonymous
    December 02, 2013
    The comment has been removed