Northfleet Northfleet - 4 months ago 13x
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 :)


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()