我正在尝试将这个VBScript代码转换成Python(Win32)代码,但是没有成功!

Dim objMain, objSysInf, stMsg

Set objMain = CreateObject("nnetcom.oMain")

Call objMain.UnlockComponent("xxx-xxxxx-xxxxx-xx")

Set objSysInf = CreateObject("nnetcom.oSystemInfo")

Call objSysInf.GetSystemInfos

stMsg = objSysInf.cOsName & " " & objSysInf.cOsType & vbCrLf & _
        objSysInf.cOsCpu & vbCrLf & objSysInf.cOsMem & vbCrLf & _
        objSysInf.cOsGpu

MsgBox stMsg, vbInformation, "System Information"

Set objSysInf = Nothing
Set objMain = Nothing

我运行的是32位Windows7,安装了Python2.7.3和PythonforWindows扩展。
另外,我通过执行“makepy.pyc”从…“Lib\site packages\win32com\client\”添加了COM对象,但运气不好,总是收到一些错误消息。。。
这是我的Python代码:
import pythoncom
import win32com.client

objMain = win32com.client.Dispach("nnetcom.oMain")

ret = objMain.UnlockComponent("xxx-xxxxx-xxxxx-xx")

objSysInf = win32com.client.Dispach("nnetcom.oSystemInfo")

objSysInf.GetSystemInfos()

stMsg = objSysInf.cOsName

print(stMsg)

有人能帮我谈这个吗?

最佳答案

Dispach应该是Dispatch

09-06 19:31