如何获取哪个硬盘的可启动硬盘或系统的主磁盘 [英] How can I get which serail number of hard disk is boot-able or primary disk of system

查看:147
本文介绍了如何获取哪个硬盘的可启动硬盘或系统的主磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取硬盘序列号以为我的应用程序生成许可证。在互联网上搜索后我发现这个



HERE



但是..使用Win32_DiskDrive管理对象我可以获得硬盘的序列号但是来自如何才能将哪个硬盘用作主磁盘?

I want to get hard disk serial number to generate a licence for my application. after searching on the internet I found this

HERE

But .. using Win32_DiskDrive management object I can get serial number of hard disk but from the list, how can get which hard disk use as primary disk ?

推荐答案

首先,在您找到的示例中,我绝不会依赖WMI查询中的条目始终是相同的顺序。 WMI查询可以包含order by子句。话虽如此,这个例子给你一个很好的起点。您需要做的是获取启动分区的磁盘驱动器索引。为此,我们需要查询 Win32_DiskPartition 类。在此类中,您正在查找 BootPartition 属性为true的驱动器索引。下面的示例代码可以帮助您。



First, in the example you found, I would never rely on the entries in the WMI queries to be always the same order. The WMI queries can have an order by clauses. With that said, that example give you an excellent starting point. What you need to do is get the index of the disk drive for the boot partition. To do that, we need to query Win32_DiskPartition class. In this class, you are looking for the drive index where the BootPartition property is true. The sample code below should help you out.

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

foreach (ManagementObject managementObject in searcher.Get())
{
    Console.WriteLine(managementObject["DeviceId"].ToString());
    Console.WriteLine(managementObject["Index"].ToString());
}

Console.WriteLine();
Console.WriteLine();
Console.WriteLine();

searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskPartition");

foreach (ManagementObject managementObject in searcher.Get())
{
    Console.WriteLine(managementObject["DeviceId"].ToString());
    Console.WriteLine(managementObject["Index"].ToString());
    Console.WriteLine(managementObject["Bootable"].ToString());
    Console.WriteLine(managementObject["BootPartition"].ToString());
}

Console.ReadKey();


谢谢
virusstorm, But I want to get the serial number for the physical DISK, from your code I can get which DRIVE is boot one, But I still stuck on how can I get the SN for the DISK that have this boo partition ?

Thanks


这篇关于如何获取哪个硬盘的可启动硬盘或系统的主磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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