从 .NET 操作 Hyper-V
.NET 应用程序有什么方法可以创建、删除、启动和停止 Hyper-V 虚拟机吗?
我想创建一种从 C# 应用程序启动和停止虚拟机的自动化方法(创建和删除是额外的好处)。我认为(至少)有一种方法可以通过 P/Invoke 执行此操作,但我找不到任何讨论如何执行此操作的内容。
最好有一些好的演练或文档的链接。
Are there any means for a .NET application to create, delete, start, and stop Hyper-V virtual machines?
I would like to create an automated means of starting and stopping (the create & delete are bonus) virtual machines from a C# application. 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.
Any links to some good walkthroughs or documentation would be preferable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
大部分 Hyper-V 自动化都是通过 WMI 实现的。 WMI 并不是明确的 .NET API,但在 .NET 中使用它非常容易。
请参阅 Hyper-V WMI API 文档 和旧版 v1 文档。
Much of the Hyper-V automation is through WMI. WMI isn't explicitly a .NET API, but it's pretty easy to work with from .NET.
See Hyper-V WMI API docs and older v1 docs.
不要忘记考虑到在最新版本的 hyper-v 中,命名空间已移至 v2。例如,Hyper-V 2008 中的命名空间为 root\virtualization,2012 年命名空间已更改为 root\virtualization\v2。(Windows
服务器版本)
检查 这篇文章了解更多详情。
这对我使用最新版本的 Hyper-V
希望有帮助。
Don't forget to take into consideration that in newest releases of hyper-v, the namespaces have been moved to 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.
This helped me a lot in newest versions of Hyper-V
Hope it helps.
System Center Virtual Machine Manager 附带了一组非常好的 .NET 程序集,您可以在应用程序中自由引用它们。它还具有出色的 Powershell 界面,可轻松编写脚本。
但是,如果您使用的是原始 Hyper-V 而不是 SCVMM,那么我不知道。看看你能否让你的老板接受 SCVMM。
System Center Virtual Machine Manager comes with a very good set of .NET assemblies, which you can freely reference in your app. It also has an excellent Powershell interface for easy scripting.
However, if you're working with raw Hyper-V and not SCVMM, then I don't know. See if you can get your boss to spring for SCVMM.
您可以用它做到这一点以及更多。 http://archive.msdn.microsoft.com/ddc
它适用于托管服务商,但可以轻松在本地安装。
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.