VBScript到Python代码段转换

时间:2012-04-22 13:13:02

标签: python com vbscript

我正在尝试将此 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

我正在运行Windows 7 32位,安装了 Python 2.7.3 Python for Windows Extensions 。 此外,我通过从... “Lib \ site-packages \ win32com \ client \”执行“makepy.pyc”添加了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)

有没有人可以帮我解决这个问题?

1 个答案:

答案 0 :(得分:4)

Dispach应该是Dispatch