options = 'Disable' ## provide your msconfig usage option here either "Enable" or "Disable"
import os
import subprocess
user_id = []

############# creating dword 32 bit in registry for user #################
def dword_32(user):
	cmd = 'reg  add  HKEY_USERS\\'+user+'\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer  /v DisallowRun /t  REG_DWORD  /d 1 /f'
	obj = subprocess.Popen(cmd, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
	res, err = obj.communicate()
	if err:
		print(err)
	else:
		return 'Success'

############ Disabling the msconfig for user ###################
def disable_msconfig(user):
	cmd = 'reg  add  HKEY_USERS\\'+user+'\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun  /v  1 /t  REG_EXPAND_SZ  /d  msconfig.exe /f'
	obj = subprocess.Popen(cmd, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
	res, err = obj.communicate()
	if err:
		print(err)
	else:
		print("Msconfig Disabled for : "+user )

def enable_msconfig(user):
	cmd = 'reg  delete  HKEY_USERS\\'+user+'\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun  /v  1 /f'
	obj = subprocess.Popen(cmd, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
	res, err = obj.communicate()
	if err:
		print(err)
	else:
		print("Msconfig Enabled for : "+user )

obj = subprocess.Popen('WMIC useraccount get name,sid', shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
out, err = obj.communicate()
if err:
	print(err)
else:
	keyword = "SID"
	before_keyword, keyword, after_keyword = out.partition(keyword)
	str1 = after_keyword.strip().splitlines()

	for i in str1:
	    if "Administrator" in i or 'DefaultAccount' in i or 'Guest' in i or 'WDAGUtilityAccount' in i :
	        pass
	    else:
	    	keyword_1 = ' '
	        before_keyword_1, keyword_1, after_keyword_1 = i.partition(keyword_1)
	        if 'S' in after_keyword_1:
	        	user_id.append(after_keyword_1.strip())

if len(user_id) > 0:
	for val in user_id:
		Dword = dword_32(val) 
		if Dword == 'Success':
			pass 
		else:
			print("Unable to create registry key for user : "+val)
			break
	if options.capitalize() == 'Disable':
		for values in user_id:
			disable_msconfig(values)
	elif options.capitalize() == 'Enable':
		for val in user_id:
			Dword = enable_msconfig(val)
	else:
		print("Please provide correct options...")

else:
	print("Something went wrong.....")
