Option Explicit
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
'读取CPU的方法
Sub GetCPUID()
Dim CPUID, strComputer As String
Dim objWMIService, colDevices, objDevice
strComputer = "."
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer)
Set colDevices = objWMIService.ExecQuery _
("Select * From Win32_Processor")
For Each objDevice In colDevices
CPUID = objDevice.ProcessorID
Next
'MsgBox "CPUID=" & CPUID
Text1.Text = CPUID
End Sub