[python-win32] Impersonating an Admin User using a standard User

Amit Arora Amit.Arora at infogain.com
Mon Apr 30 07:20:22 CEST 2007


Hi Members,

I am trying to use the Admin Privilidges of a user , by logging into the
system using a standard user......
Am using the following code for impersonation ......... Also aware of
CreateProcessAsUser , guess I am not able to figure out the correct way
to handle the admin user to do some admin task using a standard login
.....

________________________________________________________________________
___________________-
#!usr/local/bin/python

import sys , win32api , win32net , win32security , win32con , os
class Impersonate:
    def __init__(self,login,password):
	self.domain = "AARORA"
	self.login = "AdminLogin"
	self.password="top1_secret"
    def logon(self):
	
self.handel=win32security.LogonUser(self.login,self.domain,self.password
,
	
win32con.LOGON32_LOGON_INTERACTIVE,win32con.LOGON32_PROVIDER_DEFAULT)
	win32security.ImpersonateLoggedOnUser(self.handel)
    def logoff(self):
	win32security.RevertToSelf() #terminates impersonation
	self.handel.Close() #guarantees cleanup

a=Impersonate(self.login,'top1_secret')

try:
    a.logon() #become the user
    #do whatever here
    print win32api.GetUserName() #show you're someone else
    #os.system("c:\\textpad\\setup.exe")
    os.chdir("c:\\Textpad")
    os.system("start /wait setup.exe /s/a/s /sms
/f1c:\\Textpad\\settpvista.iss") 
    a.logoff() #return to normal
except:
    print sys.exc_type , sys.exc_value

________________________________________________________________________
________



Please guide me on how to install any application(or use admin
privilidges through a standard login ) .....
 

	Regards,
	~Amit Arora,
	Senior Software Engineer,
	Infogain India (P) Ltd.
	A-16, Sector-60, NOIDA - U.P. - 201301, India.
	Phone: +91-120-2445144, Extn.: 4210.
	Fax: +91-120-2580406.
	www.infogain.com
e-mail: amit.arora at infogain.com


More information about the Python-win32 mailing list