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

Home Posts Topics Members FAQ

Problem listing services with wmi

Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would
help me list and work with services on my Win32 machine. Now, everything
seems fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when
I try to run the first example which is on the first page above, I get
an error. The code is :

import wmi

c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 583, in query
raise WMI_EXCEPTIONS. get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoIni tialize () before
instantiating the WMI object) doesn't seem to work in this case. In
other words, this code :

import wmi
import pythoncom

pythoncom.CoIni tialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S

--
_______________ _______________ _____________
Jean-Sébastien Guay je******@videot ron.ca
http://whitestar02.webhop.org/

Jul 19 '05 #1
5 3178
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service ():

-Larry
Jean-Sébastien Guay wrote:
Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would
help me list and work with services on my Win32 machine. Now, everything
seems fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when
I try to run the first example which is on the first page above, I get
an error. The code is :

import wmi

for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 583, in query
raise WMI_EXCEPTIONS. get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoIni tialize () before
instantiating the WMI object) doesn't seem to work in this case. In
other words, this code :

import wmi
import pythoncom

pythoncom.CoIni tialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S

Jul 19 '05 #2
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service ():

-Larry
Jean-Sébastien Guay wrote:
Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would
help me list and work with services on my Win32 machine. Now, everything
seems fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when
I try to run the first example which is on the first page above, I get
an error. The code is :

import wmi

for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 583, in query
raise WMI_EXCEPTIONS. get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoIni tialize () before
instantiating the WMI object) doesn't seem to work in this case. In
other words, this code :

import wmi
import pythoncom

pythoncom.CoIni tialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S


Jul 19 '05 #3
Hello Larry,
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service ():


No change. For reference, the reason I know it's the c.Win32_Service ()
call that's throwing the exception is that if I try to run this :

import wmi
import pythoncom

pythoncom.CoIni tialize()
c = wmi.WMI()
services = c.Win32_Service ()
for s in services :
print s.Caption, s.State

the exception gets thrown on the "services = ..." line.

Out of curiosity, is there any reason why whitespace between the method
name and parameter list parentheses isn't good? Because the code I
posted before was copy-pasted from Tim Golden's site
(http://tgolden.sc.sabren.com/python/wmi.html) and the spaces were there.

Thanks,

J-S

--
_______________ _______________ _____________
Jean-Sébastien Guay je******@videot ron.ca
http://whitestar02.webhop.org/

Jul 19 '05 #4
I guess I was wrong and it does work, but from Python Style Guide:

Whitespace in Expressions and Statements
Pet Peeves

Guido hates whitespace in the following places:

<snip>
- Immediately before the open parenthesis that starts the argument
list of a function call, as in "spam (1)". Always write
this as "spam(1)".

<end snip>

-Larry

Jean-Sébastien Guay wrote:
Hello Larry,
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service ():


No change. For reference, the reason I know it's the c.Win32_Service ()
call that's throwing the exception is that if I try to run this :

import wmi
import pythoncom

pythoncom.CoIni tialize()
c = wmi.WMI()
services = c.Win32_Service ()
for s in services :
print s.Caption, s.State

the exception gets thrown on the "services = ..." line.

Out of curiosity, is there any reason why whitespace between the method
name and parameter list parentheses isn't good? Because the code I
posted before was copy-pasted from Tim Golden's site
(http://tgolden.sc.sabren.com/python/wmi.html) and the spaces were there.

Thanks,

J-S

Jul 19 '05 #5
The only thing I could find for the hresult is that it corresponds to
wbemErrCritical Error. According to this page
http://msdn.microsoft.com/library/de...merrorenum.asp
it's some kind of internal error.

Roger
"Jean-Sébastien Guay" <je******@video tron.ca> wrote in message
news:ma******** *************** *************@p ython.org...
Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would help
me list and work with services on my Win32 machine. Now, everything seems
fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when I
try to run the first example which is on the first page above, I get an
error. The code is :

import wmi

c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py ", line 583, in query
raise WMI_EXCEPTIONS. get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoIni tialize () before
instantiating the WMI object) doesn't seem to work in this case. In other
words, this code :

import wmi
import pythoncom

pythoncom.CoIni tialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S

--
_______________ _______________ _____________
Jean-Sébastien Guay je******@videot ron.ca
http://whitestar02.webhop.org/



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 19 '05 #6

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

Similar topics

5
569
by: fripper | last post by:
I posted this problem a couple of days ago but felt I might have better luck re-stating the problem. Apparently I messed up IIS (v. 5) somehow because I am suddenly unable to load web forms! A simple example will help. I created a simple web project that contains two simple forms ... WebForm1 and WebForm2. WebForm1 has a button which when clicked simply does a Response.Redirect("WebForm2.aspx"). When I run the program and click the...
3
2156
by: Microsoft Newsgroups | last post by:
Hi all, I'm having an interesting problem with my IE Webcontrols. I'm using the toolbar and when I test it in my browser using "http://localhost/mysite", it works fine. Incidentally, I have "mysite" set up as a web application. Now when I test it going through "http://mysite/no-ip.org" then the toolbar doesn't work properly. It seems to merely render the images and any subsequent embedded Javascript but there are no events fired to the...
12
5124
by: Joel Byrd | last post by:
I'm having a little problem with using type-ahead functionality for an auto-suggest box. Sometimes, when I start to type something and the type-ahead shows up, the AJAX will send a request query using the value that *includes* the type-ahead value. In other words, say that I type in "ja" and the first listing that comes up is "jack@test.com". The AJAX part is supposed to send "ja" as one of the query string variables when calling the...
0
2348
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they have no contents to them, i..e I can press on the File menu button, and see it depress, but the Exit...
4
2121
by: infiniti | last post by:
Hi, I am coming across problems in trying to EFFICIENTLY merge to XML files into one which involves transposing the rows into columns so that I can either generate a single flat xml file or store it in a flat table in the database. The 2 XML files which I have are: <xml> <keyword>
1
1396
by: infiniti | last post by:
Hi, I am trying to transform this xml section using xsl, but there is a glitch in the xsl file which I do not know how to rectify. Any help is appreciated. XML: <?xml version="1.0" encoding="UTF-8"?> <xml> <RelatedKeyword><Common>anushka</Common><Searches>1032</Searches></RelatedKeyword>
9
1517
by: dave m | last post by:
I have a small application that launches an application via the shell function when a listening socket receives data from another PC. This works fine using a WinForms environment. However, I want this listing app to run in the background as a service. When debugging the service, the line - ID = Shell("C:\TestApp.exe", AppWinStyle.NormalFocus) returns a PID value, executes without errors, but the program "TestApp.exe"
2
2511
by: Lionel B | last post by:
I have a function which takes a functor argument. I which to call it for a functor which is actually a class member; this works fine, using the mem_fun_ref and bind1st functions (see listing 1 below). Or, rather, it works fine as long as my member functor is const. The problem comes when I wish to use it for a *non*-const functor (see listing 2 below): *** Start listing 1 *************************************************** // test1.cpp
6
1519
by: Saqib Ali | last post by:
Hi All, I am trying to retrieve all the child domains for a given domain in a VB applications. Will something like the following do the trick? Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://" & parentDomain) Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry) Dim resEnt As SearchResult
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8732
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...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
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
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.