VB6如何获取电脑的CPU序号?
答案:2 悬赏:30 手机版
解决时间 2021-03-22 15:41
- 提问者网友:蓝莓格格巫
- 2021-03-22 12:00
VB6如何获取电脑的CPU序号?
最佳答案
- 五星知识达人网友:十鸦
- 2021-03-22 13:23
获取CPU序列号要使用 汇编指令
比较麻烦
static DWORD g_eax; // 存储返回的eax
static DWORD g_ebx; // 存储返回的ebx
static DWORD g_ecx; // 存储返回的ecx
static DWORD g_edx; // 存储返回的edx
void Executecpuid(DWORD veax)
{
asm("cpuid"
:"=a"(g_eax),
"=b"(g_ebx),
"=c"(g_ecx),
"=d"(g_edx)
:"a"(g_eax));
}
int isSupport;
void GetSerialNumber(WORD nibble[6])
{
Executecpuid(1); // 执行cpuid,参数为 eax = 1
isSupport = g_edx & (1<<18); // edx是否为1代表CPU是否存在序列号
if (FALSE == isSupport) // 不支持,返回false
{
return ;
}
Executecpuid(3); // 执行cpuid,参数为 eax = 3
memcpy(&nibble[4], &g_eax, 4); // eax为最高位的两个WORD
memcpy(&nibble[0], &g_ecx, 8); // ecx 和 edx为低位的4个WORD
比较麻烦
static DWORD g_eax; // 存储返回的eax
static DWORD g_ebx; // 存储返回的ebx
static DWORD g_ecx; // 存储返回的ecx
static DWORD g_edx; // 存储返回的edx
void Executecpuid(DWORD veax)
{
asm("cpuid"
:"=a"(g_eax),
"=b"(g_ebx),
"=c"(g_ecx),
"=d"(g_edx)
:"a"(g_eax));
}
int isSupport;
void GetSerialNumber(WORD nibble[6])
{
Executecpuid(1); // 执行cpuid,参数为 eax = 1
isSupport = g_edx & (1<<18); // edx是否为1代表CPU是否存在序列号
if (FALSE == isSupport) // 不支持,返回false
{
return ;
}
Executecpuid(3); // 执行cpuid,参数为 eax = 3
memcpy(&nibble[4], &g_eax, 4); // eax为最高位的两个WORD
memcpy(&nibble[0], &g_ecx, 8); // ecx 和 edx为低位的4个WORD
全部回答
- 1楼网友:十鸦
- 2021-03-22 13:45
1、API里有相关函数
2、VB取CPU信息源代码:
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 RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Const REG_SZ = 1
Const REG_DWORD = 4
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub Command1_Click()
Dim cpupl As String * 100
Dim ret As Long, hKey&
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\DESCRIPTION\System\CentralProcessor\0", hKey)
RegQueryValueEx hKey, "ProcessorNameString", 0, REG_SZ, ByVal cpupl, Len(cpupl)
'cpuinfo = Left(cpupl, InStr(cpupl, Chr(0)) - 1)
MsgBox cpupl
End Sub
2、VB取CPU信息源代码:
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 RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Const REG_SZ = 1
Const REG_DWORD = 4
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub Command1_Click()
Dim cpupl As String * 100
Dim ret As Long, hKey&
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\DESCRIPTION\System\CentralProcessor\0", hKey)
RegQueryValueEx hKey, "ProcessorNameString", 0, REG_SZ, ByVal cpupl, Len(cpupl)
'cpuinfo = Left(cpupl, InStr(cpupl, Chr(0)) - 1)
MsgBox cpupl
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯