我如何才能找到,而无需使用WMI在.NET中的硬盘设备序列号? [英] How can I find the Harddisk Device Serial Number without using the WMI in .NET?

查看:129
本文介绍了我如何才能找到,而无需使用WMI在.NET中的硬盘设备序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从硬盘上的硬连线的序列号,但没有使用WMI。我尝试使用WMI code,它不会在我的机器上工作的肯定。那么,有没有在.NET中查找物理硬盘的序列号的任何选择吗?

I want to get the hardwired serial number from the hard disk but NOT using WMI. I tried using WMI code, and it doesn't work on my machine for sure. So is there any alternative in .NET for finding the Serial Number of a physical hard disk?

推荐答案

粗略的:

using System;
using System.Management;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk");
            ManagementObjectCollection mcol = mangnmt.GetInstances();
            string result = "";
            foreach (ManagementObject strt in mcol)
            {
                result += "Name              : " + Convert.ToString(strt["Name"]) + Environment.NewLine;
                result += "VolumeName        : " + Convert.ToString(strt["VolumeName"]) + Environment.NewLine;
                result += "VolumeSerialNumber: " + Convert.ToString(strt["VolumeSerialNumber"]) + Environment.NewLine;
                result += Environment.NewLine;
            }
            Console.Out.WriteLine(result);
            Console.In.ReadLine();
        }
    }
}

请注意也有,你可以使用其他的属性,如果你想细节调整,以特定的磁盘,你需要做一些处理上的结果。

Note there are also other attributes you can use, and if you want the details for a specific disk you will need to do some processing on the results.

希望帮助!

这篇关于我如何才能找到,而无需使用WMI在.NET中的硬盘设备序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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