Created
April 29, 2016 20:50
-
-
Save vlad-bezden/8d21c3d454813147c2e83357b98164bd to your computer and use it in GitHub Desktop.
Example on how to add user to the group in Windows using Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Example on how to add user to the group in Python | |
# | |
import win32net | |
def add_user_to_group(domain, group, user): | |
user_group_info = { | |
'domainandname': '%s\\%s' % (domain, user) | |
} | |
try: | |
win32net.NetLocalGroupAddMembers(None, group, 3, [user_group_info]) | |
except win32net.error as error: | |
number = error.args[0] | |
if number != 1378: | |
print("Error Number: '%s'; Context: '%s'; Message: '%s'" % error.args) | |
raise | |
# function usage | |
print(add_user_to_group('SOME_DOMAIN', 'SOME_GROUP', 'SOME_USER')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks man, that really helps!