C# 如何获取使用C安装的ISO I的驱动器号#

C# 如何获取使用C安装的ISO I的驱动器号#,c#,visual-studio-2013,C#,Visual Studio 2013,我一直在做一个自动安装程序,因为我必须经常重新安装Windows,我安装的软件之一是Visual Studio 2013,它是一个ISO 我已经编写了一些装载ISO的代码,但我无法确定在运行安装程序时如何返回驱动器号 else if (soft == "Visual Studio 2013 Pro") { var isoPath = Loc.path + Loc.vs2013pro; using (var p

我一直在做一个自动安装程序,因为我必须经常重新安装Windows,我安装的软件之一是Visual Studio 2013,它是一个ISO

我已经编写了一些装载ISO的代码,但我无法确定在运行安装程序时如何返回驱动器号

else if (soft == "Visual Studio 2013 Pro")
            {
                var isoPath = Loc.path + Loc.vs2013pro;
                using (var ps = PowerShell.Create())
                {
                    ps.AddCommand("Mount-DiskImage").AddParameter("ImagePath", isoPath).Invoke();
                }
                var proc = System.Diagnostics.Process.Start(Loc.path + Loc.vs2013pro);
                proc.WaitForExit();
                System.IO.File.Copy(Loc.path + @"\Visual Studio 2013 Pro\Serial.txt", folder + "/Serials/VS2013Pro Serial.txt");
            }

添加
PassThru
参数,这将导致返回。
DevicePath
属性中有挂载点。

标记的答案对我不起作用,因此根据我在上找到的一篇博文,我决定使用C#(必需参考System.Management.Automation)将其编码为一个很好的示例& 系统、管理、自动化、运行空间)


使用Powershell,您应该能够做到这一点:
(获取卷)。DriveLetter
DevicePath对于我来说是空的/空的,使用:
var命令=ps.AddCommand(“Mount DiskImage”);AddParameter(“ImagePath”,等径);AddParameter(“PassThru”);foreach(command.Invoke()中的PSObject PSObject){var path=PSObject.Members[“DevicePath”].Value;}
        string isoPath = "C:\\Path\\To\\Image.iso";
        using (var ps = PowerShell.Create())
        {

            //Mount ISO Image
            var command = ps.AddCommand("Mount-DiskImage");
            command.AddParameter("ImagePath", isoPath);
            command.Invoke();
            ps.Commands.Clear();

            //Get Drive Letter ISO Image Was Mounted To
            var runSpace = ps.Runspace;
            var pipeLine = runSpace.CreatePipeline();
            var getImageCommand = new Command("Get-DiskImage");
            getImageCommand.Parameters.Add("ImagePath", isoPath);
            pipeLine.Commands.Add(getImageCommand);
            pipeLine.Commands.Add("Get-Volume");

            string driveLetter = null;
            foreach (PSObject psObject in pipeLine.Invoke())
            {
                driveLetter = psObject.Members["DriveLetter"].Value.ToString();
                Console.WriteLine("Mounted On Drive: " + driveLetter);
            }
            pipeLine.Commands.Clear();

            //Unmount Via Image File Path
            command = ps.AddCommand("Dismount-DiskImage");
            command.AddParameter("ImagePath", isoPath);
            ps.Invoke();
            ps.Commands.Clear();

            //Alternate Unmount Via Drive Letter
            ps.AddScript("$ShellApplication = New-Object -ComObject Shell.Application;" + 
                "$ShellApplication.Namespace(17).ParseName(\"" + driveLetter + ":\").InvokeVerb(\"Eject\")");
            ps.Invoke();
            ps.Commands.Clear();
        }