将DiskIndex映射到卷标签 [英] Map a DiskIndex to a Volume Label

查看:83
本文介绍了将DiskIndex映射到卷标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我可以使用

Current I am able to get all the Drives and their labels in c# by using the DriveInfo.GetDrives(). Then I am able to get the Disk Index / Index of the Partition by this methodology.

var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition");

foreach (var queryObj in searcher.Get())
{
    Console.WriteLine("-----------------------------------");
    Console.WriteLine("Win32_DiskPartition instance");
    Console.WriteLine("Name:{0}", (string)queryObj["Name"]);
    Console.WriteLine("Index:{0}", (uint)queryObj["Index"]);
    Console.WriteLine("DiskIndex:{0}", (uint)queryObj["DiskIndex"]);
    Console.WriteLine("BootPartition:{0}", (bool)queryObj["BootPartition"]);
}

此问题是DiskIndex,Name和Index基本上只是数字而不是卷标签,即C:\,D:\等...

The problem with this is that the DiskIndex, Name, and Index are basically just numbers and not the Volume Label i.e. C:\, D:\, etc...

因此,最重要的是,如何使

So bottom line how can I make the Volume Label which is the Name Proprty on the DriveInfo to the DiskIndex? Either using this methodology or a better way will work.

(这是对以下内容的跟踪:

(This is a follow to: Tell if a Drive is a partition or a separate HDD)

我确实找到了 Win32_LogicalDiskToPartition . LogicalDisk具有卷,而LogicalDisktoParition提供映射.但是,我似乎无法弄清楚如何获取地图.我试着寻找一个JOIN并选择值,但在不进行大量C#代码循环的情况下,找不到有关如何进行联接的任何内容.

I did find for the Management Query of the Win32_LogicalDisk and then the Win32_LogicalDiskToPartition. the LogicalDisk has the volume and the LogicalDisktoParition provides the mapping. However, I cannot seem to figure out how to get the map. I tried looking for a JOIN and selecting the values but couldn't find anything on how do this join without extensive looping in the c# code.

推荐答案

您需要使用您是正确的 Win32_LogicalDiskToPartition .是 Win32_LogicalDisk Win32_DiskPartition .在 Win32_LogicalDiskToPartition 类中,这两个属性显示了链接,

You are correct Win32_LogicalDiskToPartition. Is the link between Win32_LogicalDisk and Win32_DiskPartition. On Win32_LogicalDiskToPartition class, these two properties show the links,

PS> Get-WmiObject-Win32_LogicalDiskToPartition类

PS> Get-WmiObject -Class Win32_LogicalDiskToPartition

前提:\\ computer \ root \ cimv2: Win32_DiskPartition.DeviceID =磁盘#0,分区#1"

Antecedent : \\computer\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #1"

从属项:\\ computer \ root \ cimv2: Win32_LogicalDisk.DeviceID ="D:"

Dependent : \\computer\root\cimv2:Win32_LogicalDisk.DeviceID="D:"

只需解析这两个属性并适当过滤其他类.

Just parse these two properties and filter the the other classes appropriately.

这篇关于将DiskIndex映射到卷标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆