使用VDS创建UEFI分区

时间:2012-10-19 13:35:56

标签: c#-4.0 wmi vds uefi

我正在尝试使用IVdsCreatePartitionEx::CreatePartitionEx方法创建UEFI分区。

CREATE_PARTITION_PARAMETERS struct参数中,我将PARTITION_SYSTEM_GUID(c12a7328-f81f-11d2-ba4b-00a0c93ec93b)作为partitionTypeGPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER(0x8000000000000000)作为属性。

但我得到一个类型为c12a0000-f81f-11d2-ba4b-00a0c93ec93b的未知分区。

Screenshot of DISKPART showing error http://i49.tinypic.com/s1kzub.png

任何想法在这里可能出错?

此外,我尝试在Win8上使用WMI创建UEFI分区。 但是我得到了错误值41010 - 指定的分区类型无效。 这是我的代码

static void Main(string[] args)
{
    try
    {
        var scope = new ManagementScope(@"\\.\Root\Microsoft\Windows\Storage");
        scope.Connect();

        const string query = "SELECT * FROM MSFT_Disk WHERE Number = 7";
        var objectQuery = new ObjectQuery(query);
        var seacher = new ManagementObjectSearcher(scope, objectQuery);
        var disks = seacher.Get();

        var disk = disks.Cast<ManagementObject>().FirstOrDefault();

        if (disk == null)
        {
            throw new NoNullAllowedException("Disk is null");
        }

        var parameters = disk.GetMethodParameters("CreatePartition");
        FillInvocationParameters(parameters, new Dictionary<string, object> { { "Size", 104857600 }, { "Offset", 5ul * 1024 * 1024 * 1024 }, { "Alignment", 512 }, { "AssignDriveLetter", false }, { "GptType", "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" }, { "IsHidden", false } });

        var result = disk.InvokeMethod("CreatePartition", parameters, null);
        var returnValue = result["ReturnValue"];
    }
    catch (Exception exception)
    {
        Debug.Fail(exception.Message);
    }
}
static void FillInvocationParameters(ManagementBaseObject invokeParameters, IDictionary<string, object> parameters)
{
    foreach (var pair in parameters)
    {
        string stringParamValue;

        var managementObjectParam = pair.Value as ManagementObject;
        var arrayParam = pair.Value as string[];

        if (managementObjectParam != null)
        {
            stringParamValue = managementObjectParam.GetText(TextFormat.CimDtd20);
            invokeParameters[pair.Key] = stringParamValue;
        }
        else if (arrayParam != null)
        {
            invokeParameters[pair.Key] = arrayParam;
        }
        else if (pair.Value != null)
        {
            stringParamValue = pair.Value.ToString();
            invokeParameters[pair.Key] = stringParamValue;
        }
    }
}

1 个答案:

答案 0 :(得分:2)

我终于使用VDS解决了这个问题:我使用IVdsPack :: CreateVolume()创建了卷,接收了它的分区,使用IVdsAdvancedDisk :: FormatPartition()将其格式化为Fat32 使用IVdsAdvancedDisk2 :: ChangePartitionType()

更改了PartitionType