Northfleet Northfleet - 1 year ago 229
Python Question

Importing ctypes.windll.shell32.IsUserAnAdmin gives ImportError

Really stupid question here, sorry - it's my first day in Python.

I want to import the 'IsUserAnAdmin' function like so:

from ctypes.windll.shell32 import IsUserAnAdmin

I'm obviously doing something wrong because I'm getting:

ImportError: No module named 'ctypes.windll'

Everything works fine when I import the entirety of 'ctypes', but I don't really want to do that as I'd rather call the function with:




Could someone tell me how I should be importing this function to do this?

Thanks in advance :)

Answer Source

windll is a LibraryLoader object not a module. If you read the docs, you will notice the import been done as:

>>> from ctypes import *
>>> print windll.Shell32.IsUserAnAdmin()

windll = LibraryLoader(WinDLL) where WinDLL is a class whose doc reads:

This class represents a dll exporting functions using the Windows stdcall calling convention.

So you can do:

>>> IsUserAnAdmin = WinDLL('Shell32').IsUserAnAdmin
>>> IsUserAnAdmin()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download