text file

yqyq22 at hotmail.com yqyq22 at hotmail.com
Wed Oct 1 10:19:44 EDT 2008


On Oct 1, 4:03 pm, yqy... at hotmail.com wrote:
> HI all,
> i have some problem with the code belove, i have a list of servers in
> a textfile (elencopc.txt).... i would to retrieve informations via WMI
> ( cicle for ), but i don't understand if the code is correct:
>
> import win32com.client
> import string
> import sys
> listserver = open('c:\\elencopc.txt','r')
> objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
> objSWbemServices = objWMIService.ConnectServer(listserver,"root
> \cimv2")
> colItems = objSWbemServices.ExecQuery("Select * from
> Win32_QuickFixEngineering")
> for objItem in colItems:
>     print "Caption: ", objItem.Caption
>     print "Description: ", objItem.Description
>     print "Fix Comments: ", objItem.FixComments
>     print "HotFix ID: ", objItem.HotFixID
>     print "Install Date: ", objItem.InstallDate
>     print "Installed By: ", objItem.InstalledBy
>     print "Installed On: ", objItem.InstalledOn
>     print "Name: ", objItem.Name
>     print "Service Pack In Effect: ", objItem.ServicePackInEffect
>     print "Status: ", objItem.Status
>
> I receive the error :
> ile "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line
> 258, in _ApplyTypes_
>     result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
> retType, argTypes) + args)
> com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemLocator',
> 'The RPC server is unavailable. ', None, 0, -2147023174), None)
>
> MY big dubt is if the code is correct... because if i use vbscript all
> works fine..
> thanks a lot in advance

My problem is how to translate this vbs in python:

Dim fso
Dim strComputer
Set fso = CreateObject("Scripting.FileSystemObject")
Set ElencoPC = fso.OpenTextFile("elencoPC.txt" , 1, False)
Do Until ElencoPC.AtEndOfStream
strComputer = ElencoPC.ReadLine

thanks



More information about the Python-list mailing list