如何用VB读取计算机主板或CPU的机器码? 50
读取电脑主板或CPU的机器码哪一个更方便和稳定(更适合于软件保护)?如何用VB来编写这种代码?我不想读硬盘、网卡等信息作为机器码,只读主板或CPU就行。99tools朋友...
读取电脑主板或CPU的机器码哪一个更方便和稳定(更适合于软件保护)?如何用VB来编写这种代码?我不想读硬盘、网卡等信息作为机器码,只读主板或CPU就行。
99tools 朋友的代码固然可行,但相同配置电脑或相同CPU时读出的序列号是相同的,这就失去了实用性。我需要的是读出不同电脑的唯一的序列号。 展开
99tools 朋友的代码固然可行,但相同配置电脑或相同CPU时读出的序列号是相同的,这就失去了实用性。我需要的是读出不同电脑的唯一的序列号。 展开
2个回答
展开全部
仅仅几行代码实现取得本机CPU序列号,可以使用此序列号实现程序的注册功能。个人感觉使用CPU序列号注册比使用硬盘序列号更为适合。
'引用 Microsoft WMI Scripting v1.1 Library
'添加 Command1
Private Sub Command1_Click()
Dim cpuSet As SWbemObjectSet
Dim cpu As SWbemObject
Set cpuSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Processor")
For Each cpu In cpuSet
MsgBox "CPU系列号:" & cpu.ProcessorId 取得CPU序列号
Next
End Sub
'---------------------------------------
如果没有那个Microsoft WMI Scripting v1.1 Library ,你也可以添加工程,添加两个command和一个text,然后代码:
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0
Private Sub Command1_Click()
Dim len5 As Long, aa As Long
Dim cmprName As String
Dim osver As OSVERSIONINFO
'取得Computer Name
cmprName = String(255, 0)
len5 = 256
aa = GetComputerName(cmprName, len5)
cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)
Computer = cmprName '取得CPU端口号
Set CPUs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Processor")
For Each mycpu In CPUs
Text1.Text = mycpu.ProcessorId
Next
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
'引用 Microsoft WMI Scripting v1.1 Library
'添加 Command1
Private Sub Command1_Click()
Dim cpuSet As SWbemObjectSet
Dim cpu As SWbemObject
Set cpuSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Processor")
For Each cpu In cpuSet
MsgBox "CPU系列号:" & cpu.ProcessorId 取得CPU序列号
Next
End Sub
'---------------------------------------
如果没有那个Microsoft WMI Scripting v1.1 Library ,你也可以添加工程,添加两个command和一个text,然后代码:
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0
Private Sub Command1_Click()
Dim len5 As Long, aa As Long
Dim cmprName As String
Dim osver As OSVERSIONINFO
'取得Computer Name
cmprName = String(255, 0)
len5 = 256
aa = GetComputerName(cmprName, len5)
cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)
Computer = cmprName '取得CPU端口号
Set CPUs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Processor")
For Each mycpu In CPUs
Text1.Text = mycpu.ProcessorId
Next
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
华北工控
2023-06-12 广告
2023-06-12 广告
工控电脑是一种基于嵌入式系统的操作平台,可实现工业自动化控制领域中的各种功能,如数据采集、控制、监控、通信等。它具有稳定性高、可靠性强、扩展性好等特点,可直接支持彩色触摸屏操作,并且拥有模拟量输入、开关量输出接口,支持音视频编解码、网络化传...
点击进入详情页
本回答由华北工控提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询