戢翔 2014-04-18 06:05 采纳率: 0%
浏览 1643

C#操作Hyper-V类库,设置虚拟机硬盘路径,以及重装系统等操作

如题,在MSDN里面找到的安装虚拟硬盘路径, 但是Utility和ReturnCode这两个类没有引用,也不知道从何处来的。请教大神如何解答
using System;
using System.Management;

namespace HyperVSamples
{
class MountVHD
{
static void Mount(string path)
{
ManagementScope scope = new ManagementScope(@"root\virtualization", null);
ManagementObject imageService = Utility.GetServiceObject(scope, "Msvm_ImageManagementService");

        ManagementBaseObject inParams = imageService.GetMethodParameters("Mount");
        inParams["Path"] = path;
        ManagementBaseObject outParams = imageService.InvokeMethod("Mount", inParams, null);
        if ((UInt32)outParams["ReturnValue"] == ReturnCode.Started)
        {
            if (Utility.JobCompleted(outParams, scope))
            {
                Console.WriteLine("{0} was mounted successfully.", inParams["Path"]);
            }
            else
            {
                Console.WriteLine("Unable to mount {0}", inParams["Path"]);
            }
        }
        inParams.Dispose();
        outParams.Dispose();
        imageService.Dispose();
    }

    static void Main(string[] args)
    {
        if (args != null && args.Length != 1)
        {
            Console.WriteLine("Usage: MountVHD vhdPath");
            return;
        }
        Mount(args[0]);
    }
}

}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
    • ¥50 invest生境质量模块