简体   繁体   English

如何在不调用diskpart脚本的情况下使用C#代码挂载VHD?

[英]How do I mount a VHD using C# code without invoking a diskpart script?

In my Azure role I want to mount a VHD - roughly have an equivalent of the following diskpart commands: 在我的Azure角色中,我想挂载VHD - 大致相当于以下diskpart命令:

vdisk select VhdFilePath
vdisk attach

This answer explains how to create a script and then programmatically invoke it from C#. 这个答案解释了如何创建脚本,然后以编程方式从C#调用它。

Is there a way to achieve the same without a script - just with some .NET classes? 有没有办法在没有脚本的情况下实现相同的功能 - 只需要一些.NET类?

I don't know if there's a managed API to do this, but there are a few examples of C# wrappers around some native methods: 我不知道是否有托管API来执行此操作,但有一些C#包装器的示例围绕一些本机方法:

http://www.jmedved.com/2009/05/open-and-attach/ http://www.jmedved.com/2009/05/open-and-attach/

And since this wraps around the AttachVirtualDisk method I assume it should also work for Windows Server 2008 R2 (note that you'll need to set the osFamily of your role to 2 in order to get the R2 ). 由于这包含了AttachVirtualDisk方法,我认为它也适用于Windows Server 2008 R2(请注意,您需要将角色的osFamily设置为2才能获得R2 )。

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

相关问题 Diskpart UniqueID-C#如何获取该ID - Diskpart UniqueID - C# how to get that id 使用C#从Windows应用程序调用Java Web服务时如何在请求中设置Cookie - How do i set cookie in the request while invoking a java webservice from a windows application using c# 如何在不使用Powershell类的情况下从C#调用powershell脚本 - How do I invoke a powershell script from C# without using the Powershell class 如何在不使用 C# 中的 Main 方法的情况下运行我的代码 - 执行 Luhn 算法 - How do i run my Code without using Main method in C# - Doing a Luhn Algorithm C# 和 diskpart:如何通过磁盘标签而不是数字进行选择? - C# and diskpart: how to select by disk label and not by a number? 从C#代码调用PS脚本(Visual Studio 2017) - Invoking PS script from C# code (Visual studio 2017) 如何使用C#3.5运行SQL代码? - How do I run SQL code using c# 3.5? 如何使用代码在c#中设置输出目录? - How do I set the output directory in c# using code? 如何使用此 C# 代码创建默认构造函数? - How do I create a Default Constructor using this C# code? 如何在 PowerShell 中创建一个 Outlook 规则,该规则将 email 完美地移动到一个文件夹中,而不会出现错误,使用与 Z3D23D74EFA19FBE247 中相同的代码? - How do I create an Outlook rule in PowerShell that moves email to a folder without an error, using the same code that works in C# perfectly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM