Saberexcel - o site das macros
Esta macro com as funções e declarações retorna uma mensagem com o número do HD do seu computador mostro aqui duas funções.
Retorna o Número serial do HD do cpu
Private Declare Function GetVolumeInformation& Lib "Kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal pVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemName As Long)
Private Const MAX_FILENAME_LEN = 256
Public Function GetSerialNumber(sDrive As String) As Long
Dim ser As Long
Dim s As String * MAX_FILENAME_LEN
Dim s2 As String * MAX_FILENAME_LEN
Dim j As Long
Dim i As Long
Call GetVolumeInformation _
(sDrive + ":\", s, MAX_FILENAME_LEN, ser, i, j, s2, MAX_FILENAME_LEN)
GetSerialNumber = ser
End Function
Sub Teste_Numero_HD()
MsgBox ("Número do HD ") & GetSerialNumber("C")
MsgBox ("Número do HD ") & DriveSerialNumber("C")
End Sub
Function DriveSerialNumber(Letra)
Dim sab, d
Set sab = CreateObject("Scripting.FileSystemObject")
Set d = sab.GetDrive(sab.GetDriveName _
(sab.GetAbsolutePathName(Letra & ":\")))
DriveSerialNumber = d.SerialNumber
End Function
Aprenda tudo sobre o Aplicativo Microsoft Excel VBA com SaberExcel