本帖最后由 highflybird 于 2019-7-11 12:50 编辑
http://bbs.mjtd.com/thread-85042-1-2.html
参考上面的帖子。
- (setq scr (vlax-create-object "ScriptControl"))
- (vlax-put scr 'language "VBS")
- (setq str "Set mc=GetObject(\"Winmgmts:\")")
- (vlax-invoke scr 'EXECUTESTATEMENT str)
- (setq objWMI (vla-eval scr "mc"))
- (setq objCPU (vlax-invoke objWMI 'InstancesOF "Win32_Processor"))
- (vlax-for obj objCPU
- (alert (vlax-get obj 'ProcessorId))
- )
- (vlax-release-object objCPU)
- (vlax-release-object objWMI)
- (vlax-release-object scr)
下面的代码更有通用性。
-
- (defun C:CPUId (/ WMI svr CPU s c)
- (vl-load-com)
- (setq WMI (vlax-create-object "WbemScripting.SWbemLocator"))
- (setq svr (VLAX-INVOKE WMI 'ConnectServer ))
- (setq CPU (vlax-invoke svr 'ExecQuery "Select ProcessorId from Win32_Processor"))
- (vlax-for item CPU
- (setq c (vlax-get item 'ProcessorId))
- (setq s (cons c s))
- )
- (vlax-release-object CPU)
- (vlax-release-object svr)
- (vlax-release-object wmi)
- (car s)
- )
|