谁有用纯API获取CPU序列号,不能用WMI

lpb830820 2008-07-21 05:32:57
谁有用纯API获取CPU序列号,不能用WMI,因为我不知道WMI打包时需要打包什么文件。
...全文
707 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouweizhu 2008-08-20
  • 打赏
  • 举报
回复
哎,貌似都是执行汇编指令“CPUID”
还没发现API……
Michael_g 2008-08-20
  • 打赏
  • 举报
回复
http://download.it168.com/07/0709/34267/34267_4.shtml
这个网址有个 DLL文件 可以获取CPUR 信息,用法及在VB里的调用方法,里面全都有
Michael_g 2008-08-20
  • 打赏
  • 举报
回复
CPU 序列号应该 是获取不到的
Michael_g 2008-08-20
  • 打赏
  • 举报
回复
应该 是没有这样的API,不过你可以读注册表中的值来确定计算机上有几个CPU,以及类型。
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor 项下有几个项就有几个CPU ,第一个CPU的项名是0 ,第二个是1,即
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0 存储的是第一个CPU的信息
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\1 存储的是第二个CPU的信息

例如:
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
"Component Information"=hex:00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00
"Identifier"="x86 Family 15 Model 107 Stepping 1" ;标识
"Configuration Data"=hex(9):ff,ff,ff,ff,ff,ff,ff,ff,00,00,00,00,00,00,00,00
"ProcessorNameString"="AMD Athlon(tm) 64 X2 Dual Core Processor 4400+" ;CPU 的名字
"VendorIdentifier"="AuthenticAMD" ;制造商
"FeatureSet"=dword:a0057fff
"~MHz"=dword:000009ca ;主频
"Update Status"=dword:00000001

lorl2 2008-08-20
  • 打赏
  • 举报
回复
不是所有的电脑都有CPUID给你读的
lfm13720 2008-08-20
  • 打赏
  • 举报
回复
cpu-z 很好很强大,不过没源码,应该不是用API做的。
嗷嗷叫的老马 2008-07-22
  • 打赏
  • 举报
回复
哦嘿嘿,这个代码可不简单哪.

而且貌似AMD的CPU不好读?
lpb830820 2008-07-22
  • 打赏
  • 举报
回复
我觉得还是用API比较安全,实在。但我在网上搜索过,没找到。
lpb830820 2008-07-22
  • 打赏
  • 举报
回复
happy_sea :WMI依赖的是哪个服务?是Windows Management Instrumentation服务吗?我同事的电脑上该服务已经运行了。再者,我发布程序给客户的话,如果客户的电脑的服务没有启动的话那总不能去启动吧,有可能客户会认为我们的软件有问题。
红叶哥 2008-07-22
  • 打赏
  • 举报
回复
路過
happy_sea 2008-07-22
  • 打赏
  • 举报
回复
那应该是他的WMI服务被禁用了。
lpb830820 2008-07-22
  • 打赏
  • 举报
回复
首先谢谢 Modest,不过提供的代码例子只是获取CPU的名称,我想要的是获取CPU的唯一序列号。

happy_sea :我编译了一个小程序给我的同事,他的电脑是XP系统的,运行到GetObject代码时提示不能创建对象。
vansoft 2008-07-22
  • 打赏
  • 举报
回复
有读硬盘出厂ID的代码
应该有CPU的代码

到老外的网上搜索看看
嗷嗷叫的老马 2008-07-22
  • 打赏
  • 举报
回复
呕噎~~~~~~
迈克揉索芙特 2008-07-21
  • 打赏
  • 举报
回复

作者: Vxk/CVC.GB
下面的例子完全用VB进行ASM编程的示例,本例获得CPU ID.
工程文档分为一个form1.frm 和一个模块module1.bas

----------------------form1.frm的源文档---------------------

VERSION 5#
Begin VB.form form1
Caption = "form1"
ClientHeight = 1965
ClientLeft = 60
ClientTop = 345
ClientWidth = 3105
LinkTopic = "form1"
ScaleHeight = 1965
ScaleWidth = 3105
StartUpPosition = 2 'Bildschirmmitte
Begin VB.CommandButton Command1
Caption = "Get CPU Name"
Height = 495
Left = 840
TabIndex = 0
Top = 315
Width = 1425
End
Begin VB.Label Label2
Alignment = 2 'Zentriert
AutoSize = -1 'True 中国网管联盟
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 1515
TabIndex = 2
Top = 1065
Width = 60
End
Begin VB.Label Label1
Alignment = 2 'Zentriert
AutoSize = -1 'True
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False


EndProperty
Height = 285
Left = 1515
TabIndex = 1
Top = 1350
Width = 75
End
End
Attribute VB_Name = "form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)

Label1 = ""
Label2 = ""

End Sub

Private Sub Command1_Click()

Label1 = GetCpuName() & " CPU"
Label2 = "You have a" & IIf(InStr("AEIOU", Left$(Label1, 1)), "n", "")

End Sub
------------------------------end---------------------------------


www_bitscn_com
下面是modu1e.bas的源代码

----------------------module1.bas的源文档--------------------------
Option Explicit
'
'This shows how to incorporate machine code into VB
'''''''''''''''''''''''''''''''''''''''''''''''''''
'The example fills the array with a few machine instructions and then copies
'them to a procedure address. The modified procedure is then called thru
'CallWindowProc. The result of this specific machine code is your CPU Vendor Name.
'
'##########################################################################
'Apparently it gets a Stack Pointer Error, but I don't know why; if anybody
'can fix that please let me know...             UMGEDV@AOL.COM
'The Error is not present in the native compiled version; so I think it got
'something to do with the P-Code Calling Convention (strange though)...
'##########################################################################
'
'Sub Dummy serves to reserve some space to copy the machine instructions into. www.bitsCN.com
'
'
'Tested on Intel and AMD CPU's (uncompiled and compiled)
'
'
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private x As Long

Public Function GetCpuName() As String

Dim MachineCode(0 To 35) As Byte
Dim VarAddr As Long
Dim FunctAddr As Long
Dim EAX As Long
Dim CPUName(1 To 12) As Byte

'set up machine code

MachineCode(0) = &H55 'push ebp

MachineCode(1) = &H8B 'move ebp,esp
MachineCode(2) = &HEC

MachineCode(3) = &H57 'push edi


MachineCode(4) = &H52 'push edx

MachineCode(5) = &H51 'push ecx

MachineCode(6) = &H53 'push ebx

MachineCode(7) = &H8B 'move eax,dword ptr [ebp+8]
MachineCode(8) = &H45
MachineCode(9) = &H8

MachineCode(10) = &HF 'cpuid
MachineCode(11) = &HA2

MachineCode(12) = &H8B 'mov edi,dword ptr [ebp+12]
MachineCode(13) = &H7D
MachineCode(14) = &HC

MachineCode(15) = &H89 'move dword ptr [edi],ebx
MachineCode(16) = &H1F

MachineCode(17) = &H8B 'mov edi,dword ptr [ebp+16]
MachineCode(18) = &H7D
MachineCode(19) = &H10

MachineCode(20) = &H89 'move dword ptr [edi],ecx
MachineCode(21) = &HF

MachineCode(22) = &H8B 'mov edi,dword ptr [ebp+20]

MachineCode(23) = &H7D
MachineCode(24) = &H14

MachineCode(25) = &H89 'move dword ptr [edi],edx
MachineCode(26) = &H17

MachineCode(27) = &H58 'pop ebx

MachineCode(28) = &H59 'pop ecx

MachineCode(29) = &H5A 'pop edx

MachineCode(30) = &H55 'pop edi

MachineCode(31) = &HC9 'leave

MachineCode(32) = &HC2 'ret 16   I tried everything from 0 to 24
MachineCode(33) = &H10 '      but all produce the stack error
MachineCode(34) = &H0

'tell cpuid what we want
EAX = 0

'get address of Machine Code
VarAddr = VarPtr(MachineCode(0))

'get address of Sub Dummy
FunctAddr = GetAddress(AddressOf Dummy)

'copy the Machine Code to where it can be called
CopyMemory ByVal FunctAddr, ByVal VarAddr, 35 '35 bytes machine code

'call it
On Error Resume Next 'apparently it gets a stack pointer error when in P-Code but i dont know why
CallWindowProc FunctAddr, EAX, VarPtr(CPUName(1)), VarPtr(CPUName(9)), VarPtr(CPUName(5))
'Debug.Print Err; Err.Description
'MsgBox Err & Err.Description
On Error GoTo 0

GetCpuName = StrConv(CPUName(), vbUnicode) 'UnicodeName

End Function

Private Function GetAddress(Address As Long) As Long

GetAddress = Address

End Function

Private Sub Dummy()

'the code below just reserves some space to copy the machine code into
'it is never executed

x = 0
x = 1
x = 2
x = 3
x = 4
x = 5
x = 6
x = 7
x = 8
x = 9
x = 10
x = 0
x = 1
x = 2
x = 3
x = 4
x = 5
x = 6
x = 7
x = 8
x = 9
x = 10

End Sub

happy_sea 2008-07-21
  • 打赏
  • 举报
回复
Win 2K/XP和Win98都支持WMI,不需要专门打包什么文件。

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧