Determine if the current user is in the Administrators group (Windows / Python)

I want certain functions in my application to be available only if the current user is an administrator.

How to determine if the current user is in the local administrators group using Python on Windows?

+4
source share
2 answers

You can try this :

import ctypes print ctypes.windll.shell32.IsUserAnAdmin() 
+6
source
 import win32net def if_user_in_group(group, member): members = win32net.NetLocalGroupGetMembers(None, group, 1) return member.lower() in list(map(lambda d: d['name'].lower(), members[0])) # Function usage print(if_user_in_group('SOME_GROUP', 'SOME_USER')) 

Of course, in your case, "SOME_GROUP" will be the "administrator"

0
source

Source: https://habr.com/ru/post/1304173/


All Articles