'引用api獲得硬盤序列號
網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序定制開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了海西免費建站歡迎大家使用!
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 "C硬盤序列號-機器碼啦-(16制): " Hex(硬盤序列號)
End Sub
很難達到你的要求的,VB好像是獲取不到硬盤的物理序列號的,只能獲取到某一個分區(qū)的序列號.不過可以調(diào)用其它的程序?qū)懙墨@取硬盤物理序列號的dll來獲取,CPU的序列號我用的是wmi.VB本來對底層方面就不是很好
引用api獲得硬盤序列號
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 "C硬盤序列號-機器碼啦-(16制): " Hex(硬盤序列號)
End Sub
電腦沒有機器碼的,我們所說的機器碼指對電腦的配件(如硬盤)型號按一定算法演算出的代碼.通常不同軟件演算出的機器碼都是不一樣的,下面三個函數(shù)分別得到本機IP,電腦名稱,硬盤Id.(硬盤id可做機器碼)Public Function GetIPAddress() As String'得到IPSTRComputer = "."
Set OBJWMIService = GetObject("winmgmts:" "{impersonationLevel=impersonate}!\\" STRComputer "\root\cimv2")Set IPConfigSet = OBJWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") For Each IPConfig In IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress) GetIPAddress = IPConfig.IPAddress(i) Next End IfNext
End Function
Public Function GetUserName() As String'得到電腦名稱STRComputer = "."
Set OBJWMIService = GetObject("winmgmts:\\" STRComputer "\root\CIMV2")Set ColCSItems = OBJWMIService.ExecQuery("SELECT * From Win32_ComputerSystem")For Each OBJCSItem In ColCSItems GetUserName = OBJCSItem.UserNameNext
End Function
Public Function GetDiskID(Disk As String) As String'得到磁盤IDDim Flag As BooleanDim DiskID As String
Flag = FalseOn Error GoTo label
DiskID = Str(CreateObject("Scripting.FileSystemObject").GetDrive(Disk).SerialNumber)
Flag = Truelabel:If Flag Then GetDiskID = DiskIDElse GetDiskID = "" x = MsgBox("Function Parameter Like C " + Chr(10) + Chr(13) + "Please Check The Existence Of The " + Disk + " Disk", vbInformation + vbOKOnly, "Microsoft Excel 5.0")End If
End Function