windows script host and python

bowman bowman at montana.com
Sun Mar 18 16:21:57 CET 2001


Tim Roberts <timr at probo.com> wrote in message
> >
> >Here, for example, is the "list all running processes" WMI scripting
> >example translated into Python:
>
> Cool!  Is this supposed to be NT-only?  It doesn't fly on my Win98 box.

http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/ms
dn-files/027/001/576/msdncompositedoc.xml

don't know if that reference will work. if not, go to msdb.microsoft.com,
click on 'downloads' and
look for 'Windows Management Instrumentation'. ignore the pessimistic blurb
about Win98 SE.

no. there is a core WMI that installs on Win9.x and NT. I don't believe it
is on NT4.0 by default, but can be installed there. The SDK will install on
NT also, but i'm not sure it will install on Win9.x. The problem is the SDK
contains the .chm file that is required reading for playing around. it is
available on line at msdn.microsoft.com. It is a part of 2000/ME.

the WMI is ms's shot at WBEM. The long form to invoke it would be (sorry
'bout the Perl, but the Python calls are very similar):


$locator = Win32::OLE->new("WbemScripting.SWbemLocator");
if (!defined $locator) {
  die "couldn't get the locator object";
}

$server = $locator->ConnectServer();
if (!defined $server) {
  die "couldn't get the server object";
}

$processes = $server->InstancesOf("Win32_process");
if (!defined $processes) {
  die "couldn't get the processes";
}

The whole thing is pretty integral to the Win2000 world view. The idea is to
reduce TCO by allowing the sysadmin to query all systems in the net. WMI
probably gets into the AD implementation,too.
wbem is an industry initiative, so in theory one could use the locator to
connect to a linux, mac, etc server and access CIM data in a platform
independent way.

I recently did a unix style 'ps' for NT/2000 in C, and it was about 200
lines of pretty arcane calls into the HKEY_PERFORMANCE_DATA, psapi, ntdll
etc to get stuff like the parent pid, user name, ccommand line, etc, with
WMI, it take about 10 lines of Python/Perl/JScript/VBScript. the scripts are
a little slower, with the native WSH engines and Perl the fastest, and
Python lagging a bit. Still quite usable on a 233 mhz Win95 box.





More information about the Python-list mailing list