Importing WMI module into Python CGI script fails

Tim Golden tim.golden at
Mon Jul 21 10:14:05 CEST 2003

"MK" <MK at> wrote in message news:<bfeobb$dtsku$1 at>...
> "Peter Hansen" <peter at> 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.


More information about the Python-list mailing list