WMI获取磁盘的GUID路径
Windows支持一种特殊的UNC (Universal Naming Convention)路径表示法:\\?\Volume{
获取到磁盘的GUID路径
Caption:盘符
DeviceID:GUID路径
例如:
SelectQuery selectQuery = new
SelectQuery("Win32_Volume");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(selectQuery);
foreach (ManagementObject disk in searcher.Get())
{
tmpArray.Add(disk.Properties["Caption"].Value.ToString());
tmpArray2.Add(disk.Properties["DeviceID"].Value.ToString());
}
SelectQuery("Win32_Volume");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(selectQuery);
foreach (ManagementObject disk in searcher.Get())
{
tmpArray.Add(disk.Properties["Caption"].Value.ToString());
tmpArray2.Add(disk.Properties["DeviceID"].Value.ToString());
}
Windows Management Instrumentation (WMI)
class Win32_Volume : CIM_StorageVolume { uint16 Access; uint16 Availability; uint64 BlockSize; string Caption; uint32 ConfigManagerErrorCode; boolean ConfigManagerUserConfig; string CreationClassName; string Description; boolean ErrorCleared; string ErrorDescription; string ErrorMethodology; datetime InstallDate; uint32 LastErrorCode; string Name; uint64 NumberOfBlocks; string PNPDeviceID; uint16[] PowerManagementCapabilities; boolean PowerManagementSupported; string Purpose; string Status; uint16 StatusInfo; string SystemCreationClassName; string SystemName; string DeviceID; uint64 Capacity; boolean Compressed; string DriveLetter; uint32 DriveType; string FileSystem; uint64 FreeSpace; boolean IndexingEnabled; boolean DirtyBitSet; string Label; uint32 MaximumFileNameLength; boolean Automount; boolean QuotasEnabled; boolean QuotasIncomplete; boolean QuotasRebuilding; uint32 SerialNumber; boolean SupportsDiskQuotas; boolean SupportsFileBasedCompression;
};
更多详细:参考MSDN
http://msdn.microsoft.com/en-us/library/aa394515(VS.85).aspx
注意:Windows XP and earlier: This class is not available.
XP或之前的版本,不受支持
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构