|
本帖最后由 fxl447098457 于 2024-4-11 10:02 编辑
我这段代码应该通用了。试试。
Const HKEY_LOCAL_MACHINE = &H80000002
Sub 获取machineid()
Dim objCtx As Object, strOSArch, objLocator As Object, objStdRegProv As Object, Inparams As Object, Outparams As Object
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
strOSArch = GetOSArch '获取操作系统位数
objCtx.Add "__ProviderArchitecture",strOSArch '这一句设置读取的注册表位置,设置64即为读取64位注册表
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objStdRegProv = objLocator.ConnectServer(".", "root\default", "", "", , , , objCtx).Get("StdRegProv")
Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
Inparams.Hdefkey = HKEY_LOCAL_MACHINE
Inparams.Ssubkeyname = "SOFTWARE\Microsoft\SQMClient"
Inparams.Svaluename = "MachineId"
Set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams, , objCtx)
MsgBox "MachineId:" & Outparams.SValue
Set Outparams = Nothing
Set Inparams = Nothing
Set objStdRegProv = Nothing
Set objLocator = Nothing
Set objCtx = Nothing
End Sub
Function GetOSArch() As Integer '获取系统是32位还是64位
GetOSArch = Val(GetObject("winmgmts:root\cimv2:Win32_OperatingSystem=@").OSArchitecture)
End Function |
评分
-
2
查看全部评分
-
|