473,756 Members | 9,334 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.t xt','w').write( '\r\n'.join(out ))
print 'View classes.txt in a browser'
---------------------------
import wmi
c = wmi.WMI()
for x in c.Win32_Network Adapter():
print x
--------------------------
Jul 18 '05 #1
6 7199
"Colin Brown" <cb****@metserv ice.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(lstSup pr=[]):
import win32com,win32c om.client
WMIService
=win32com.clien t.GetObject(r'w inmgmts:{impers onationLevel=im personate}!//.\r
oot\cimv2')
listProcess = WMIService.Exec Query('Select * from Win32_Process')
for item in listProcess:
print ''
print 'Nom :',item.Name
print 'Ligne de commande :',item.Command Line
print 'Descriptif :',item.Descrip tion
print 'Path d\'exécution :',item.Executa blePath
print 'Statut :',item.Status
print 'Pririté :',item.Priorit y
print 'Caption :',item.Caption
print 'IdProcess :',item.Process Id
print 'IdProcess Parent :',item.ParentP rocessId
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.goog le.com...
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_Environme nt (Google Win32_Environme nt) 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/scripting061120 02.asp

http://msdn.microsoft.com/library/de...us/dnclinic/ht
ml/scripting081320 02.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/scripting061120 02.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****@metserv ice.com> wrote in message news:<3f******@ news.iconz.co.n z>...
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/scripting061120 02.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
1491
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, and I know there's lots of sample code out there I can grab if I ever need to. Equally, I think I've got the simpler concepts about creating Windows
4
2810
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 available here or is either too costly. Thanks in advance ---------- http://www.aqod.com/?p=11 - An absolute beginners tutorial using VB.NET..
2
3291
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. then i used the windowsservice.exe in setup deployment project.
17
2239
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
2000
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 from the localhost. However when I connect from a remote client, I either get a socket error or an xmlrpclib.ProtocolError error. If I use serve_forever() rather than handle_request(), the remote clients can connect but it breaks the Windows...
3
1953
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. I.E. It won't authenticate. Is there a way to do Windows authentication using the built-in VS 2005 test server? Thanks in advance. Tom --
1
1693
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: jobsgooogle@gmail.com Consultant Jobs Gooogle (Nick Name)
4
7961
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; open failed. reason: no such file or directory at ... line xx. If I place the node name in place of the $node, it works fine.
0
1171
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
9303
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
9117
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
8542
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...
1
7078
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
6390
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
4955
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
5156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2508
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.