473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

text file

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.SWbemLocat or")
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
Oct 1 '08 #1
3 1768
On Oct 1, 4:03*pm, yqy...@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.SWbemLocat or")
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
Oct 1 '08 #2
On Wed, 01 Oct 2008 07:19:44 -0700, yqyq22 wrote:
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
Oct 1 '08 #3
yq****@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:

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
Oct 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
1
by: Rigga | last post by:
Hi, I am new to Python and need to parse a text file and cut parts out i.e. say the text file contained 5 rows of text: line 1 of the text file line 2 of the text file line 3 of the text...
27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
16
by: thenightfly | last post by:
Ok, I know all about how binary numbers translate into text characters. My question is what exactly IS a text character? Is it a bitmap?
7
by: Chris | last post by:
Hi I can use a text file as a datasource but am unable to get the datatable to see the text file as having multiple columns. Everything gets put into the first column in the datatable. Sample of...
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
1
by: Osoccer | last post by:
...to a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem: I need a...
10
by: bluemountain | last post by:
Hi there, Iam new to python forms and programming too I had a text file where i need to extract few words of data from the header(which is of 3 lines) and search for the keyword TEXT1, TEXT2,...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.