Note that there are some explanatory texts on larger screens.

plurals
  1. POPython WMI calls not working under Windows 7
    primarykey
    data
    text
    <p>I've run into a sticky problem using WMI (via win32com) in Python under Windows 7. I haven't been able to find a resolution for this.</p> <p>Here is my code:</p> <pre><code>from win32com.client import GetObject def get_printers(computer): """ Get a list of printers from the specified computer name. """ wmiservice = GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" + computer + r"\root\cimv2") return wmiservice.ExecQuery("Select * from Win32_Printer") for printer in get_printers("ps2"): print printer.Name </code></pre> <p>This works great under Windows XP. But fails miserably if I run this under Windows 7:</p> <pre><code>Traceback (most recent call last): File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript exec codeObject in __main__.__dict__ File "C:\Python27\sample\temp2.py", line 8, in &lt;module&gt; for printer in get_printers("ps2"): File "C:\Python27\sample\temp2.py", line 5, in get_printers wmiservice = GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" + computer + r"\root\cimv2") File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 72, in GetObject return Moniker(Pathname, clsctx) File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 87, in Moniker moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname) com_error: (-2147024891, 'Access is denied.', None, None) </code></pre> <p>I tried everything I can think of in Win 7: disabled firewall (no virus scanner), ensured DCOM is enabled, ensured WMI is enabled, and disabled UAC. Any help would be greately appreciated.</p> <p>Note: I'm using Python 2.7.1 with pywin32 build 215, under Windows 7 Ultimate x86 (and Windows XP SP3).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload