|
CPU ID两种方法:
- Public Function GetCpuIdwmi() As String '只返回CPU0
- GetCpuIdwmi = GetObject("winmgmts:").ExecQuery("Select ProcessorID From Win32_Processor")("Win32_Processor.DeviceID='CPU0'", 1).ProcessorID
- End Function
复制代码- Private s1 As Long, s2 As Long, s3 As Long, s4 As Long
- Private Function GetStrFromPtr(ByVal Ptr As Long) As String '从指针得到字符串
- Dim Buffer() As Byte 'GetCpuID函数使用
- Dim lpSize As Long
- lpSize = lstrlenW(Ptr) * 2
- If lpSize <> 0 Then
- ReDim Buffer(lpSize)
- CopyMemory VarPtr(Buffer(0)), Ptr, lpSize
- GetStrFromPtr = Buffer
- End If
- End Function
- Private Function GetHex(ByRef inByte() As Byte) As String '将字节数据以十六进制字符串输出
- Dim i As Long, j() As String, k As Long 'GetCpuID函数使用
- ReDim j(UBound(inByte))
- For i = 0 To UBound(j)
- j(i) = "00"
- RSet j(i) = CStr(Hex(inByte(i)))
- Next
- ReDim Preserve j(UBound(j) - 2)
- GetHex = Replace(Join(j(), "-"), " ", "0")
- End Function
- Private Function Int2Hex(Value As Long, n As Long) As String 'GetCpuID函数使用
- Dim tmp1 As String, tmp2 As String, i As Long
- tmp1 = Right("0000000" + Hex(Value), n)
- For i = 0 To Len(tmp1) / 2 - 1
- tmp2 = tmp2 + Mid(tmp1, Len(tmp1) - 1 - 2 * i, 2)
- Next i
- Int2Hex = tmp2
- End Function
- Private Function hFormat(s As String) As String 'GetCpuID函数使用
- Dim str1 As String
- Dim n As Long
- n = 8 - Len(s)
- If n = 0 Then
- str1 = s
- Else
- str1 = s
- For i = 1 To n
- str1 = "0" & str1
- Next i
- End If
- hFormat = str1
- End Function
- Public Function GetCpuId() As String
- mm:
- Dim Code As String, Exec() As Byte
- Dim tmp_Addr As Long
- Dim str1 As String, str2 As String, str3 As String, str4 As String
- Code = "B80000000033D20FA28915" & Int2Hex(VarPtr(s1), 8) & "A3" & Int2Hex(VarPtr(s2), 8) & "B80100000033C933D20FA28915" & Int2Hex(VarPtr(s3), 8) & "890D" & Int2Hex(VarPtr(s4), 8) & "C3"
- ReDim Exec(Len(Code) / 2 - 1)
- For i = 0 To Len(Code) / 2 - 1
- Exec(i) = Int("&H" & Mid(Code, i * 2 + 1, 2))
- Next
- tmp_Addr = VirtualAllocEx(-1, ByVal 0&, UBound(Exec) + 1, MEM_COMMIT, PAGE_EXECUTE_READWRITE)
- WriteProcessMemory -1, ByVal tmp_Addr, ByVal VarPtr(Exec(0)), UBound(Exec) + 1, ByVal 0&
- CreateRemoteThread -1, ByVal 0&, 0, ByVal tmp_Addr, ByVal 0&, ByVal 0&, ByVal 0&
- If s1 = 0 Then GoTo mm '获取有错,返回重新获取
- GetCpuId = hFormat(Hex(s1)) & hFormat(Hex(s2)) & hFormat(Hex(s3)) & hFormat(Hex(s4))
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|