2

I'm trying to convert this VBScript code to Python (Win32) code but with no luck!

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

I'm running Windows 7 32-bit with Python 2.7.3 and Python for Windows Extensions installed. Also I added COM object by executing "makepy.pyc" from ..."Lib\site-packages\win32com\client\" and with no luck, always getting some error message...

Here is my Python code:

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)

Is there anybody who can help me with this conversation?

2
  • 2
    Please show full error output. Commented Apr 22, 2012 at 13:14
  • Hi Marcin Here is the error output: C:\>c:\Progra~1\Python\python.exe c:\example2.py Traceback (most recent call last): File "c:\example2.py", line 4, in <module> objMain = win32com.client.Dispach("nnetcom.oMain") AttributeError: 'module' object has no attribute 'Dispach' Can you help me out? Ragards, Viktor Commented Apr 22, 2012 at 13:27

1 Answer 1

4

Dispach should probably be Dispatch.

Sign up to request clarification or add additional context in comments.

8 Comments

Ohh my God, what a Typo I made there!!! :D Its working now, but how to make line breaks and new lines like in my VBScript code posted above? Thanks for helping me out! ;)
You can use the methods of the built-in str type, as well as the common sequence operations to split a string into the required lines. See §5.6 of the documentation of the Python standard library. Put those lines in a list. Then use '\n'.join() (maybe use '\r\n'.join() on Windows) to make a new string that contains the strings from the list, separated by newlines.
By line breaks and new lines I meant, how to write shorter line of code like in my VBScript example, see: stMsg =
You can use the format method of the str object, or concatenate strings using the + operator.
Ah. Use the textwrap module. (see §7.7 of the Python standard library docs)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.