VB应用程序中如何验证硬盘物理序列号?

VB应用程序中如何验证硬盘物理序列号这是知道号的代码.PrivateDeclareFunctionMymachineCLib"kernel32"Alias"GetVolu... VB应用程序中如何验证硬盘物理序列号
这是知道号的代码.
Private Declare Function MymachineC Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Form_Load()
Dim AA, 硬盘序列号, Maxlen, Sysflag As Long: Dim VolName, FsysName As String
AA = MymachineC("c:\", VolName, 256, 硬盘序列号, Maxlen, Sysflag, FsysName, 256)
MsgBox "你的机器码: " & Hex(硬盘序列号)
End
End Sub

注明:在VB生成的工程中里就事先写上这个物理号,怎么怎么验证.验证错误提示电脑重启.
上面的代码是看物理号的一个应用程序

现在要验证的是另一个程序.发完全代码.
展开
 我来答
孙阿武
2010-04-27 · TA获得超过281个赞
知道小有建树答主
回答量:141
采纳率:0%
帮助的人:161万
展开全部
Imports System.Management
Imports System.IO
Imports ErrPlug = CC.PublicTools.StrEdit.ErrorStr

Partial Public Class HardWare

Public Sub New()
MyBase.New()
End Sub

Public Class HardDiskInfo

Public Sub New()
MyBase.New()
End Sub

Public Class HardDrive

Public Sub New()
MyBase.New()
End Sub

''' <summary>
''' 返回单个的硬盘信息。
''' </summary>
''' <remarks></remarks>
Public Class _HardDrive

Public Sub New()
MyBase.New()
End Sub

Public DriveID As Integer
Public TotalSize As String
Public DiskTypes As String
Public DiskModel As String
Public FingerKey As String
Public Overloads Function ToString() As String
Return String.Format("DiskID:{0}|Type:{1}|Model:{2}|Size:{3}|FigSn:{4}", DriveID, DiskTypes, DiskModel, TotalSize, FingerKey)
End Function
End Class

''' <summary>
''' 执行获取磁盘硬盘信息的过程函数。
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function DoGetHardDriveInfo() As List(Of _HardDrive)
Dim ResultDriveList As List(Of _HardDrive) = New List(Of _HardDrive)
Try
Dim query As New SelectQuery("Win32_DiskDrive")
Using search As New ManagementObjectSearcher(query)
Dim ITempa As Integer = 0
For Each info In search.Get()
ITempa += 1
Application.DoEvents()
' ResultDiskList.AllDiskCount += 1
Dim NewDisk As _HardDrive = New _HardDrive() With {.DriveID = ITempa}
If info("TotalSectors") IsNot Nothing Then
NewDisk.TotalSize = StrEdit.NumConvert.FormatBytes(CDbl((CType(info("TotalSectors"), UInt64) * CType(info("BytesPerSector"), UInt32))))
Else
NewDisk.TotalSize = "Unknown"
End If
If info("InterfaceType") IsNot Nothing Then
NewDisk.DiskTypes = info("InterfaceType").ToString
Else
NewDisk.DiskTypes = "Unknown"
End If
If info("Model") IsNot Nothing Then
NewDisk.DiskModel = info("Model").ToString
Else
NewDisk.DiskModel = "Unknown"
End If
If info("signature") IsNot Nothing Then
NewDisk.FingerKey = info("signature").ToString
Else
NewDisk.FingerKey = "Unknown"
End If
ResultDriveList.Add(NewDisk)
Next
End Using
Catch ex As Exception
ErrPlug.WriteErrorLog(ex)
End Try
Return ResultDriveList
End Function

End Class

Public Class DiskPart

Public Sub New()
MyBase.New()
End Sub

Public Class _DiskPart

Public Sub New()
MyBase.New()
End Sub

Public PartLetter As String
Public PartType As String
Public PartFileSystem As String
Public PartIsReady As Boolean
Public PartLabel As String
Public PartTotalSize As String
Public PartUsedSize As String
Public PartFreeSize As String
Public PartSerialNo As String
Public PartFressPersent As String
Public Overloads Function ToString() As String
Return "Name:" & PartLetter & "|Type:" & PartType & "|F.S.:" & PartFileSystem & "|IsReady:" & PartIsReady & "|Label:" & PartLabel & _
"|Total:" & PartTotalSize & "|Used:" & PartUsedSize & "|Free:" & PartFreeSize & "|SN:" & PartSerialNo & "|FreeP:" & PartFressPersent
End Function
End Class

''' <summary>
''' 执行返回磁盘分区信息的列表。
''' </summary>
''' <remarks></remarks>
Public Shared Function DoGetDiskPartList() As List(Of _DiskPart)
Dim ResultPartList As List(Of _DiskPart) = New List(Of _DiskPart)

Try
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim CurDriver As DriveInfo

For Each CurDriver In allDrives
Application.DoEvents()

Dim NewPart As _DiskPart = New _DiskPart() With {.PartLetter = CurDriver.RootDirectory.ToString, .PartType = CurDriver.DriveType.ToString}
If CurDriver.IsReady = True Then
NewPart.PartFileSystem = CurDriver.DriveFormat
Else
NewPart.PartFileSystem = ""
End If
NewPart.PartIsReady = CurDriver.IsReady
If CurDriver.IsReady = True Then
NewPart.PartLabel = CurDriver.VolumeLabel
Else
NewPart.PartLabel = ""
End If
If CurDriver.IsReady = True Then
NewPart.PartTotalSize = StrEdit.NumConvert.FormatBytes(CDbl(CurDriver.TotalSize))
Else
NewPart.PartTotalSize = ""
End If
If CurDriver.IsReady = True Then
NewPart.PartFreeSize = StrEdit.NumConvert.FormatBytes(CDbl(CurDriver.TotalFreeSpace))
Else
NewPart.PartFreeSize = ""
End If
If CurDriver.IsReady = True Then
NewPart.PartUsedSize = StrEdit.NumConvert.FormatBytes(CDbl(CurDriver.TotalSize - CurDriver.TotalFreeSpace))
Else
NewPart.PartUsedSize = ""
End If
If CurDriver.IsReady = True Then
NewPart.PartFressPersent = String.Format("{0}%", FormatNumber(CDbl(CurDriver.TotalFreeSpace / CurDriver.TotalSize * 100), 1))
Else
NewPart.PartFressPersent = "0.00%"
End If
If CurDriver.IsReady = True Then
NewPart.PartSerialNo = GetVolumeSerialNumber(CurDriver.RootDirectory.ToString)
Else
NewPart.PartSerialNo = ""
End If
ResultPartList.Add(NewPart)
Next

Catch ex As Exception
ErrPlug.WriteErrorLog(ex)
End Try
Return ResultPartList
End Function

End Class

''' <summary>
''' 获取硬盘序列号。
''' </summary>
''' <param name="lpRootPathName"></param>
''' <param name="lpVolumeNameBuffer"></param>
''' <param name="nVolumeNameSize"></param>
''' <param name="lpVolumeSerialNumber"></param>
''' <param name="lpMaximumComponentLength"></param>
''' <param name="lpFileSystemFlags"></param>
''' <param name="lpFileSystemNameBuffer"></param>
''' <param name="nFileSystemNameSize"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Integer, ByRef lpVolumeSerialNumber As Integer, _
ByRef lpMaximumComponentLength As Integer, ByRef lpFileSystemFlags As Integer, _
ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Integer) As Integer

''' <summary>
''' 获取硬盘序列号
''' </summary>
''' <param name="volume">volume "drive letter"</param>
Public Shared Function GetVolumeSerialNumber(ByVal volume As String) As String
Dim check As Integer
Dim volumeSerialNumber As Integer
Dim unused As String
Dim volumeName As String

Try
' Pad the strings.
volumeName = Space(14)
unused = Space(32)
check = GetVolumeInformation(volume, volumeName, Len(volumeName), _
volumeSerialNumber, 0, 0, unused, Len(unused))
' Error check.
If check = 0 Then
Return ""
Else
Return Hex(volumeSerialNumber)
End If
Catch
Return ""
End Try
Return ""
End Function

End Class

End Class
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式