VB6如何获取电脑的CPU序号?
展开全部
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
展开全部
获取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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询