VB.NET中的硬盘序列号 [英] Hard Drive Serial Number in VB.NET

查看:324
本文介绍了VB.NET中的硬盘序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

是否可以通过vb.net获取硬盘序列号?

如果有可能我可以获得它?



最好的问候,

解决方案

你不搜索吗?



如何检索REAL硬盘序列号 [ ^ ]

获取没有WMI的物理硬盘序列号 [ ^ ]

从Windows Management Instrumentation检索信息 [ ^ ]

你可以找到更多在CP& Google



代码转换

将C#转换为VB.NET [ ^ ]


Thatraja没有提及,可能不知道的是,这些方法不适用于所有硬盘驱动器。



总的来说,我认为有4种不同的方法可以检索硬盘序列号,只要它们不在RAID配置中。



哪种方法有效取决于驱动器。没有办法提前告诉哪些有效,哪些无效。您必须编写代码来尝试所有4种方法,然后评估实际值的返回数据。



不,我没有示例代码。


我更喜欢(并使用)以下函数:



 公共 功能 GetDriveSerialNumber()作为 字符串 
Dim DriveSerial 作为 整数
' 创建FileSystemObject对象
Dim fso 作为 对象 = CreateObject( Scripting.FileSystemObject
Dim Drv As Object = fso.GetDrive(fso.GetDriveName(Application.StartupPath))
使用 Drv
如果 .IsReady 那么
DriveSerial = .SerialNumber
其他 ' 驱动器未就绪!
DriveSerial = -1
结束 如果
结束 使用
返回 DriveSerial.ToString( X2
结束 功能





也许Thread-Starter也喜欢它......

Hi all visitors
Is it possible to get hard drive serial number by using vb.net?
if it is possible how i can get it?

Best Regards,

解决方案

Don't you search?

How to Retrieve the REAL Hard Drive Serial Number[^]
Get Physical HDD Serial Number without WMI[^]
Retrieving Information From Windows Management Instrumentation[^]
You can find more in CP & Google

For Code conversion
Convert C# to VB.NET[^]


What thatraja didn't mention, and probably doesn't know about, is that these methods don't work for all hard drives.

Overall, there are I think 4 different methods for retrieving the hard drive serial number, so long as they are not in a RAID configuration.

Which of the methods works depends on the drive. There is no way to tell ahead of time which will work and which don't. You'd have to write code to try all 4 methods, then evaluate the return data for your actual value.

No, I don't have example code.


I prefer (and use) the following function :

Public Function GetDriveSerialNumber() As String
     Dim DriveSerial As Integer
     'Create a FileSystemObject object
     Dim fso As Object = CreateObject("Scripting.FileSystemObject")
     Dim Drv As Object = fso.GetDrive(fso.GetDriveName(Application.StartupPath))
     With Drv
         If .IsReady Then
             DriveSerial = .SerialNumber
         Else    '"Drive Not Ready!"
             DriveSerial = -1
         End If
     End With
     Return DriveSerial.ToString("X2")
 End Function



Perhaps the Thread-Starter likes it too ...


这篇关于VB.NET中的硬盘序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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