Created
April 12, 2011 11:10
-
-
Save r4vi/915335 to your computer and use it in GitHub Desktop.
checks if the current logged in user is removed from the local administrators group and re-adds. (windows)
This file contains 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
import ctypes | |
import win32net, win32api | |
import time | |
current_user = win32api.GetUserNameEx(2) | |
data = [{"domainandname": current_user}] | |
def get_members(group_name): | |
members = win32net.NetLocalGroupGetMembers(None, group_name, 3)[0] | |
print members | |
return [x['domainandname'].lower() for x in members] | |
def is_user_in_group(username, groupname): | |
return username.lower() in get_members(groupname) | |
print 'checking if current user %s has admin rights' % (current_user,) | |
while True: | |
if (is_user_in_group(current_user, 'Administrators')): | |
pass # user is already an admin | |
else: | |
print 'User has been removed from local administrators. Re-adding' | |
if (not is_user_in_group(current_user, 'Administrators')): | |
win32net.NetLocalGroupAddMembers(None, 'Administrators', 3, data) | |
print 'SUCCESS' | |
else: | |
print 'FAILED' | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the idea being that you just run this forever. When an automated script removes you, it adds you back. this is because you actually only lose your administrator status when you log-in again.