硬盘或硬盘驱动器的序列号
乍一看,这似乎是一个非常简单的问题,有些人可能试图给我尝试谷歌的建议,可能确实如此。 但对我来说这很难,我尝试了 Google、Stack Overflow,但找不到任何好的解决方案。
只想使用 C# 获取硬盘或硬盘的序列号
请仔细阅读:硬盘的序列号,但不是硬盘卷的序列号(例如 C、D、E 等)。
为了获取硬盘卷的序列号,我在网上找到了解决方案,它工作得很好,但问题在于获取硬盘的序列号。
有些机构可能会尝试将此问题作为以下 Stake Overflow 问题的可能副本,或者可能会建议该问题的链接。但事实并非如此,
并且以下任何问题都没有为 C# 中的此问题提供良好的解决方案:
At first it may seems it is very easy question and some body may be trying to give me advice to try Google, it may be so.
But for me it is very hard I have try Google, Stack Overflow and can’t find any good solution.
Just want to get Serial number of Hard Disk or Hard Drive using C#
Please read carefully: serial number of Hard Disk, but not Serial number of Volume of Hard Disk (e.g. C, D, E, etc).
For getting serial no of volume of hard disk I have found solution on net and its work well but problem is with Getting serial number of Hard Disk.
Some body may trying to make this question as possible copy of below Stake Overflow question or may suggest link of that question. But it is not
And not any below question provides good solution for this problem in C#:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是最终的解决方案:
Get Physical HDD Serial Number without WMI
写这么多代码:
别忘了添加对
DriveInfoEx.dll
的引用。This is the final solution:
Get Physical HDD Serial Number without WMI
write this much code:
Don't forgot to add reference to the
DriveInfoEx.dll
.看到这个
只需从那里下载演示并选择“数据存储”选项卡并从中选择Win32_DiskDrive,您将获得下面提到的所有磁盘驱动器(硬盘)的信息,并在sectorpertrack之后和签名属性之前看到一个属性“SerialNumber”...
see this
just download demo from there and select "data storage" tab and select Win32_DiskDrive from this you will get information all the Disk drives(HardDisk) mention below and see one property "SerialNumber" after sectorpertrack and before signature property...
我发现的最好方法是:
从 此处
将 .dll 添加到您的项目
添加以下代码:
[DllImportAttribute("HardwareIDExtractorC.dll")]
public static extern String GetIDESerialNumber(byte DriveNumber);
从需要的地方调用硬盘ID:
GetIDESerialNumber(0).Replace(" ", string.Empty);
注意:在资源管理器中转到 dll 的属性,并将
Build Action
设置为Embedded Resource
。The best way I found is:
Download the .dll from here
Add the .dll to your project
Add this code:
[DllImportAttribute("HardwareIDExtractorC.dll")]
public static extern String GetIDESerialNumber(byte DriveNumber);
Call the hard disk ID from where you need it:
GetIDESerialNumber(0).Replace(" ", string.Empty);
Note: Go to the properties of the dll in explorer and set
Build Action
toEmbedded Resource
.我用 ILSpy (http://ilspy.net/) 查看了 System.IO.DriveInfo 类,我想出去
这段代码似乎工作正常:
I took a look with ILSpy (http://ilspy.net/) to System.IO.DriveInfo class and I figured out
this code that seems to work fine :
我找到了一个非常好的库,可以满足您的要求: https: //www.nuget.org/packages/Hardware.Info/10.0.1?_src=template
I found a very good library that do what you want : https://www.nuget.org/packages/Hardware.Info/10.0.1?_src=template