text file

Y

yqyq22

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
 
Y

yqyq22

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
 
L

Lie Ryan

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

try this:

fso = open('elencoPC.txt', 'r')
for line in f:
strComputer = line
 
T

Tim Golden

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:


Try this, using http://timgolden.me.uk/python/wmi.html :

<code>
import wmi

#
# For the test to work
#
open ("elencopc.txt", "w").write ("localhost")

for server in open ("elencopc.txt").read ().splitlines ():
c = wmi.WMI (server)
print "SERVER:", server
for item in c.Win32_QuickFixEngineering ():
print item # or print item.Caption, etc.
print
print

</code>

If you get RPC Server unavailable, it usually means that
the WMI service isn't running on that machine. Usually.

TJG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top