473,657 Members | 2,993 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\\elenc opc.txt','r')
objWMIService = win32com.client .Dispatch("Wbem Scripting.SWbem Locator")
objSWbemService s = objWMIService.C onnectServer(li stserver,"root
\cimv2")
colItems = objSWbemService s.ExecQuery("Se lect * from
Win32_QuickFixE ngineering")
for objItem in colItems:
print "Caption: ", objItem.Caption
print "Descriptio n: ", objItem.Descrip tion
print "Fix Comments: ", objItem.FixComm ents
print "HotFix ID: ", objItem.HotFixI D
print "Install Date: ", objItem.Install Date
print "Installed By: ", objItem.Install edBy
print "Installed On: ", objItem.Install edOn
print "Name: ", objItem.Name
print "Service Pack In Effect: ", objItem.Service PackInEffect
print "Status: ", objItem.Status

I receive the error :
ile "C:\Python25\Li b\site-packages\win32c om\client\dynam ic.py", line
258, in _ApplyTypes_
result = self._oleobj_.I nvokeTypes(*(di spid, 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 1773
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:\\elenc opc.txt','r')
objWMIService = win32com.client .Dispatch("Wbem Scripting.SWbem Locator")
objSWbemService s = objWMIService.C onnectServer(li stserver,"root
\cimv2")
colItems = objSWbemService s.ExecQuery("Se lect * from
Win32_QuickFixE ngineering")
for objItem in colItems:
* * print "Caption: ", objItem.Caption
* * print "Descriptio n: ", objItem.Descrip tion
* * print "Fix Comments: ", objItem.FixComm ents
* * print "HotFix ID: ", objItem.HotFixI D
* * print "Install Date: ", objItem.Install Date
* * print "Installed By: ", objItem.Install edBy
* * print "Installed On: ", objItem.Install edOn
* * print "Name: ", objItem.Name
* * print "Service Pack In Effect: ", objItem.Service PackInEffect
* * print "Status: ", objItem.Status

I receive the error :
ile "C:\Python25\Li b\site-packages\win32c om\client\dynam ic.py", line
258, in _ApplyTypes_
* * result = self._oleobj_.I nvokeTypes(*(di spid, 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("S cripting.FileSy stemObject")
Set ElencoPC = fso.OpenTextFil e("elencoPC.txt " , 1, False)
Do Until ElencoPC.AtEndO fStream
strComputer = ElencoPC.ReadLi ne

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("S cripting.FileSy stemObject") Set ElencoPC =
fso.OpenTextFil e("elencoPC.txt " , 1, False) Do Until
ElencoPC.AtEndO fStream
strComputer = ElencoPC.ReadLi ne

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_QuickFi xEngineering ():
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
61369
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: in_file = raw_input("What is the name of the file you want to open: ") in_file = open("test.txt","r")
1
9222
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 file line 4 of the text file line 5 of the text file
27
4927
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 any solid reasons to prefer text files over binary files files?
16
2658
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
4342
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 code and text file included. Please help Regards
3
2159
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 figure out why any help would be much apprechiated 1. Dim line_num As Integer 2. Dim filename2 As String 3.
1
4749
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 Visual Basic Script file, call it "Move and Reformat Text File.VBS," that will run from a Windows Script Host command-prompt-based version as follows: C:\> Cscript.exe "Move and Reformat Text File.VBS" The objective of the VBScript file, "Move...
10
3190
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, TEXT3in entire file(file consisting of 150 lines) that is related to a particular id and get the sum of the, WRITES of TEXT1, TEXT2, TEXT3 ex: input file will be as below Windows 2000 text text text text text text text
0
10751
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.