Importing WMI module into Python CGI script fails

Tim Golden tim.golden at viacom-outdoor.co.uk
Mon Jul 21 04:14:05 EDT 2003


"MK" <MK at foo.com> wrote in message news:<bfeobb$dtsku$1 at ID-174077.news.uni-berlin.de>...
> "Peter Hansen" <peter at engcorp.com> wrote
> 
> [...]
> 
> Hello Peter! This is what I get back in browser's window:
> 
> 
> 
[ ... snip masses of traceback stuff ...]

Well, in general if something works in the interpreter and not in CGI,
it's down to permissions or environment or both, ie either the user
running the CGI lacks some privilege which you (in the interpreter)
have, or there's some environment variable or registry setting which
is set for your user and not for the CGI user. The latter is less
likely for Windows.

As a starting point, try pulling the latest version of the module
(version 0.3) which allows you to pass in a ready-made WMI object
which you can construct with a user name. Get that working in
interactive mode, and then see if it works in CGI.

Something like this:
import wmi
import win32com.client

loc = win32com.client.Dispatch ("WbemScripting.SWbemLocator")
svc = loc.ConnectServer ("vodev1", "", "goldent", "password")
vodev1 = wmi.WMI (wmi=svc)

# Do stuff

NB This won't work for a connection to a local machine (not even if
you try to pretend it's a remote machine). If that's what you want to
do, you'll probably need to Google for WMI security to discover how to
allow whatever user the CGI is running under access to the WMI stuff.

TJG




More information about the Python-list mailing list