import os
import subprocess

try:
	obj = subprocess.Popen("net localgroup Administrators",shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
	result,error=obj.communicate()
	if error:
		print(error)
	else:
		val = result.replace("The command completed successfully.","")
		keyword = "-------------------------------------------------------------------------------"
		before_keyword, keyword, after_keyword = val.partition(keyword)
		value = (after_keyword.strip()).split("\n")
		for i in value:
			org_val = i.strip()
			if org_val == "Administrator" :
				pass
			elif org_val == "IAP":
				pass
			else:
				cmd = "net localgroup Administrators"+" "+org_val+" "+"/del"
				command = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
				result_1,error_1 = command.communicate()
				if error_1:
					print(error_1)
				else:
					pass
		print("All Users have been demoted to Standard users except IAP")

except Exception as e:
	print(e)
