passwd="admin@123"#specify the new password for admin account to be changed. 
account=""#specify the account which you want to change the password or else leave it blank if single admin acc is present 
import os
from subprocess import PIPE,Popen
import time
start=time.time()


u_fil_a_usr=os.popen("net localgroup Administrators ").read().split()[15:-4]
fil_a_usr=[]
if u_fil_a_usr:
    for i in u_fil_a_usr:
        if i!='Administrator' and i!='DefaultAccount':
            fil_a_usr.append(i)
if len(fil_a_usr)>2:
    print "More than one user admin account exist in this Desktop."
    print "Kindly Specify which account you want to change the password."
elif len(account)>1:
    obj=Popen('net user "%s" "%s"'%(account,passwd),shell=True,stdout=PIPE,stderr=PIPE)
    r,e=obj.communicate()
    if e:
        print e
    else:
        if r:
            print r
            print "Password changed successfully for the user %s"%account
            #print "Restarting the system "
            #print os.popen("shutdown /r").read()
        else:
            print "Password changed successfully for the user %s"%account
            #print "Restarting the system "
            #print os.popen("shutdown /r").read()
else:
    admin_acc=fil_a_usr[0].strip()
    obj=Popen('net user "%s" "%s"'%(admin_acc,passwd),shell=True,stdout=PIPE,stderr=PIPE)
    r,e=obj.communicate()
    if e:
        print e
    else:
        if r:
            print r
            print "Password changed successfully for the user %s"%admin_acc
            #print "Restarting the system "
            #print os.popen("shutdown /r").read()
        else:
            print "Password changed successfully for the user %s"%admin_acc
            #print "Restarting the system "
            #print os.popen("shutdown /r").read()
            
    
end=time.time()
print("Execution time: %s"%(end-start))