简体   繁体   English

从 .NET 操作 Hyper-V

[英]Manipulate Hyper-V from .NET

Are there any means for a .NET application to create, delete, start, and stop Hyper-V virtual machines? .NET 应用程序是否有任何方法可以创建、删除、启动和停止 Hyper-V 虚拟机?

I would like to create an automated means of starting and stopping (the create & delete are bonus) virtual machines from a C# application.我想创建一种从 C# 应用程序启动和停止(创建和删除是奖励)虚拟机的自动化方法。 I figured that (atleast) there would be a means of doing this via P/Invoke, but I cannot find anything discussing how to do this.我认为(至少)有一种通过 P/Invoke 执行此操作的方法,但我找不到任何讨论如何执行此操作的方法。

Any links to some good walkthroughs or documentation would be preferable.任何指向一些好的演练或文档的链接都是可取的。

Much of the Hyper-V automation is through WMI.许多 Hyper-V 自动化是通过 WMI 实现的。 WMI isn't explicitly a .NET API, but it's pretty easy to work with from .NET. WMI 不是明确的 .NET API,但它很容易从 .NET 使用。

See Hyper-V WMI API docs and older v1 docs .请参阅 Hyper-V WMI API 文档较早的 v1 文档

Don't forget to take into consideration that in newest releases of hyper-v, the namespaces have been moved to v2.不要忘记考虑到在 hyper-v 的最新版本中,命名空间已移至 v2。 For example from root\\virtualization in Hyper-V 2008, the namespace has changed into root\\virtualization\\v2 in 2012. (Windows Server version) Check this post for more details.例如,从 Hyper-V 2008 中的 root\\virtualization,命名空间在 2012 年已更改为 root\\virtualization\\v2。(Windows Server 版本)查看此帖子了解更多详细信息。

This helped me a lot in newest versions of Hyper-V这对我最新版本的 Hyper-V 有很大帮助

Hope it helps.希望能帮助到你。

用于Hyper-V的C#中的WMI包装器可从http://hypervlib.codeplex.com获得

System Center Virtual Machine Manager comes with a very good set of .NET assemblies, which you can freely reference in your app. System Center Virtual Machine Manager 附带了一组非常好的 .NET 程序集,您可以在您的应用程序中自由引用它们。 It also has an excellent Powershell interface for easy scripting.它还具有出色的 Powershell 界面,可轻松编写脚本。

However, if you're working with raw Hyper-V and not SCVMM, then I don't know.但是,如果您使用原始 Hyper-V 而不是 SCVMM,那么我不知道。 See if you can get your boss to spring for SCVMM.看看你能否让你的老板为 SCVMM 加油。

You can do that and much more with this.你可以做到这一点,还有更多。 http://archive.msdn.microsoft.com/ddc It is for hosters but can be easily installed on premise. http://archive.msdn.microsoft.com/ddc它适用于托管商,但可以轻松地在本地安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM