如何在VB当中获得cpu id?

casear_huang 2004-01-14 10:42:28
如何在VB当中获得cpu id?最好能够提供源代码。
...全文
871 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
leeyun 2004-08-19
  • 打赏
  • 举报
回复
mark
casear_huang 2004-02-02
  • 打赏
  • 举报
回复
不好意思,过年回家了,到现在才给分。
华芸智森 2004-01-19
  • 打赏
  • 举报
回复
使用 GetCPU.dll 吧.里面有关于CPU的一切信息.如有ID号,主频,外频,缓冲,SSE,SSE2几乎一百多项信息.
如果要,给我EMAIL:CJWA@21CN.COM 注明:GETCPU.DLL
chinaren502 2004-01-19
  • 打赏
  • 举报
回复
过年了,开心一点,很多不愉快是大环境造成的,不要想多了

一句话,只要有朋友,什么都会好的!

新年快乐!
hisofty 2004-01-19
  • 打赏
  • 举报
回复
vb内嵌汇编好复杂的
ysp2004 2004-01-15
  • 打赏
  • 举报
回复
'*******放在模块中,这种方式最容易实现******
Public Declare Function GetVolumeInformation& Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal pVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long)
Public Const MAX_FILENAME_LEN = 256



Private Sub Command1_Click()
Dim RetVal As Long
Dim str As String * MAX_FILENAME_LEN
Dim str2 As String * MAX_FILENAME_LEN
Dim A As Long
Dim B As Long
Dim sDrv As String
Dim j, CPUid As String
sDrv = "d"
Call GetVolumeInformation(sDrv & ":\", str, MAX_FILENAME_LEN, RetVal, A, B, str2, MAX_FILENAME_LEN)
CPUid = Abs(RetVal)'这就是CPUid
End Sub
flc 2004-01-15
  • 打赏
  • 举报
回复
学习
goodname008 2004-01-15
  • 打赏
  • 举报
回复
内嵌汇编的代码编译后就不行了。 :(
SoHo_Andy 2004-01-15
  • 打赏
  • 举报
回复
'用WMI,记得先工程-引用 Microsoft WMI Scripting V1.1 Library
'以下是获得CPU ID

Private Sub Command1_Click()
wmiProcessorInfo
End Sub

Private Sub wmiProcessorInfo()

Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject

Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_Processor")

On Local Error Resume Next

For Each obj In wmiObjSet
MsgBox obj.ProcessorId
Next
End Sub

看看我的文章

在VB中使用WMI获取系统硬件和软件有关信息
http://www.csdn.net/Develop/read_article.asp?id=23371
cso 2004-01-15
  • 打赏
  • 举报
回复
晕~~楼上的,这是磁盘吧~~我们正在说CPU呢~~~老大
87721054 2004-01-14
  • 打赏
  • 举报
回复
参考
http://www.dapha.net/down/list.asp?id=1564
cso 2004-01-14
  • 打赏
  • 举报
回复
VB很难,只有调用VC的DLL了
下面的例子完全用VB进行ASM编程的示例,本例获得CPU ID.


工程文件分为一个form1.frm 和一个模块module1.bas

----------------------form1.frm的源文件---------------------

VERSION 5.00
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---------------------------------





下面是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.
'
'
'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

1,485

社区成员

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

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