473,511 Members | 14,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tip: Windows internals using wmi


Recently I was looking for remote management tools and came across
"Windows Management Instrumentation". There is a python interface
available:

http://tgolden.sc.sabren.com/python/wmi.html

I was amazed how easy it became to access just about anything under
the hood (later versions of NT, 2000, XP) using a couple of lines of code!
If you have privileged access to remote computers you can interrogate
them as well. My attempts to modify things were less successful :-(

Colin Brown
PyNZ

With python, win32all and wmi installed, try these code snippets
to get some idea of what is available:

-------------------------------
import wmi
w = wmi.WMI()
for process in w.Win32_Process():
if process == 'python':
print process
-------------------------------
import wmi
c = wmi.WMI()
list = c.classes
out = []
for item in list:
if item[:1] <> '_':
out.append(item)

open('classes.txt','w').write('\r\n'.join(out))
print 'View classes.txt in a browser'
---------------------------
import wmi
c = wmi.WMI()
for x in c.Win32_NetworkAdapter():
print x
--------------------------
Jul 18 '05 #1
6 7187
"Colin Brown" <cb****@metservice.com> wrote in message news:<3f********@news.iconz.co.nz>...
Recently I was looking for remote management tools and came across
"Windows Management Instrumentation". There is a python interface
available:

http://tgolden.sc.sabren.com/python/wmi.html

I was amazed how easy it became to access just about anything under
the hood (later versions of NT, 2000, XP) using a couple of lines of code!


Well it's always nice to know one's code is being
used - thank you for the free advertising! Just in
case it wasn't well-known, you can get WMI patches
for Win9x and NT4 (not 3.51, I think) which is
essential for those of us still running quite a number
of older machines.

I suspect you've already seen it, but the cookbook page
(http://tgolden.sc.sabren.com/python/wmi_cookbook.html)
is always happy to receive new examples of things you've
found useful. Just email me with your examples.

The business of remote administration can be quite
a pain. You need to go through the levels of WMI,
DCOM, NT/2K(3) and possibly AD security to get the
access you want. I'm trying to put together a useful
hints page - any experience you have (good or bad)
will be gratefully received.

TJG
Jul 18 '05 #2
Hi

This run OK on my Windows-XP, but no-run on Windows-2000 :
def wprocess(lstSuppr=[]):
import win32com,win32com.client
WMIService
=win32com.client.GetObject(r'winmgmts:{impersonati onLevel=impersonate}!//.\r
oot\cimv2')
listProcess = WMIService.ExecQuery('Select * from Win32_Process')
for item in listProcess:
print ''
print 'Nom :',item.Name
print 'Ligne de commande :',item.CommandLine
print 'Descriptif :',item.Description
print 'Path d\'exécution :',item.ExecutablePath
print 'Statut :',item.Status
print 'Pririté :',item.Priority
print 'Caption :',item.Caption
print 'IdProcess :',item.ProcessId
print 'IdProcess Parent :',item.ParentProcessId
if item.name in lstSuppr:
try:
item.Terminate()
except:
pass
#wprocess()
wprocess(['notepad.exe','WINWORD.EXE']) # supprime certains process

@-salutations
--
michel Claveau
Jul 18 '05 #3
Can WMI be used to change environment variables such as PATH.
The Environment Variables Dialog in Windows is complete crap.
I might like to write a new environment variable editor in Python.
Jul 18 '05 #4
"MetalOne" <jc*@iteris.com> wrote in message
news:92*************************@posting.google.co m...
Can WMI be used to change environment variables such as PATH.
The Environment Variables Dialog in Windows is complete crap.
I might like to write a new environment variable editor in Python.


----------------------------------------------------------------------------
---------------------------
Hi MetalOne

I am not an expert on wmi having only just chanced upon it myself. However
some quick browsing gives:

The documentation for Win32_Environment (Google Win32_Environment) says that
wmi returns registry
information but does not provide methods for changing them.

From: http://support.microsoft.com/default...-us;Q322756#3f
Use Windows Management Instrumentation
Windows Management Instrumentation (WMI) is a component of the Microsoft
Windows operating system and is the Microsoft implementation of Web-Based
Enterprise Management (WBEM). WBEM is an industry initiative to develop a
standard technology for accessing management information in an enterprise
environment. You can use WMI to automate administrative tasks (such as
editing the registry) in an enterprise environment. You can use WMI in
scripting languages that have an engine on Windows and handle Microsoft
ActiveX objects. You can also use the WMI Command-Line utility (Wmic.exe) to
modify the Windows registry.

For additional information about WMI, visit the following Microsoft Web
site:
http://msdn.microsoft.com/library/en...start_page.asp

For additional information about the Wmic.exe, click the following article
number to view the article in the Microsoft Knowledge Base:
290216 A Description of the Windows Management Instrumentation Command-Line
Utility

Following down these links gets to:

http://msdn.microsoft.com/library/de...us/dnclinic/ht
ml/scripting06112002.asp

http://msdn.microsoft.com/library/de...us/dnclinic/ht
ml/scripting08132002.asp

These are well worth a look if you want to know what wmi is all about. Table
1 indicates that you use the "Registry provider" wmi interface for
modifying registry settings. I do not know if the python wmi interface
supports this.

There is a utility for testing wmi: run wbemtest
Colin Brown
PyNZ

Jul 18 '05 #5

Thanks for your comments Tim. Sadly I find myself in the same position
as yourself with regard to need and time to investigate this further.

I note that there is a third article in WMI Scripting Primer's:

http://msdn.microsoft.com/library/de...us/dnclinic/ht
ml/scripting06112002.asp

which states:
"Modifying the Properties of a Managed Resource
In Windows 2000, WMI is primarily a read-only technology. Of the 4,395
properties defined in the Windows 2000 root\cimv2 namespace, only 39
properties are writeable. Those numbers improve in Microsoft® Windows® XP,
where 145 of approximately 6560 properties are writeable. And the numbers
get even better in Windows Server 2003."

It appears to be evolving technology, currently targetted more at inspection
than management!

Colin Brown
PyNZ

Jul 18 '05 #6
"Colin Brown" <cb****@metservice.com> wrote in message news:<3f******@news.iconz.co.nz>...
Thanks for your comments Tim. Sadly I find myself in the same position
as yourself with regard to need and time to investigate this further.

I note that there is a third article in WMI Scripting Primer's:

http://msdn.microsoft.com/library/de...us/dnclinic/ht
ml/scripting06112002.asp

which states:
"Modifying the Properties of a Managed Resource
In Windows 2000, WMI is primarily a read-only technology. Of the 4,395
properties defined in the Windows 2000 root\cimv2 namespace, only 39
properties are writeable. Those numbers improve in Microsoft® Windows® XP,
where 145 of approximately 6560 properties are writeable. And the numbers
get even better in Windows Server 2003."

It appears to be evolving technology, currently targetted more at inspection
than management!

Colin Brown
PyNZ


Interesting indeed. Further investigation
(which I *really* didn't have the time to do!)
threw up several articles by Microsoft which
talked about having to compile / set something
up / register COM services / other arcane stuff
in order to use the Registry provider.

I can't lay my hands on the URL (and it would
have changed by the time you read this) but it
put me off somewhat -- also, I can't understand
why they didn't just build it in from the start:
it's not as though the Registry is some little-used
backwater of the Operating System!

If you come across anything useful, or find the
energy to get something working with this, let me
know.

Thanks. TJG
Jul 18 '05 #7

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

Similar topics

0
1451
by: David Mitchell | last post by:
Hello group, I'm trying to create a TCP server using Python, and I want it to run under Windows as a service. Now, I'm fine with building the TCP server using Python - done it lots of times,...
4
2793
by: Midhun K Menon | last post by:
Is there anyone who could direct me to an absolute beginners course in Windows Programming using C++? Links would be more welcome than Book names, because much of the foreign books aren't locally...
2
3261
by: raghavendra | last post by:
Hi, How to run automatically windows service by using setup deployment insatllation script using visual studio 2003.? What i did is :-- 1. created a windows service & tested the same. 2....
17
2213
by: Venkatesh | last post by:
Hi All I am a newbie to C# .I am currently developing windows application.Can anyone suggest good books or links for developing Windows Applications using C#.
0
1984
by: JDF | last post by:
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client...
3
1945
by: Tom | last post by:
I'm building a web application using VS 2005. This application uses Windows authentication to 'authenticate'. However, when I test it (debug) via the VS 2005 built-in test server, it doesn't work....
1
1674
by: Jobs Gooogle | last post by:
Skills: .Net VC++ Java C++ Windows Internals Unix Internals Location: Bangalore, Hyderabad, Delhi (NCR), Chennai Experience: 3+ Yrs Hand-On Please forward your profiles to mailto:...
4
7942
by: roblenator | last post by:
I am trying to access files on a remote windows server using the following code; my $node = 'server5'; opendir(DIR, '\\$node\C$\Servers') or warn "open failed. reason: $!"; I get an error;...
0
1160
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi again misters, I try install my windows service using MSI (setup project) I read this article http://msdn.microsoft.com/en-us/library/bb332338.aspx
0
7237
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
7137
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...
0
7417
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...
1
7074
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
7506
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...
0
5659
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,...
1
5063
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...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
445
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...

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.