[python-win32] Impersonation and Threads
Matt Herbert (matherbe)
matherbe at cisco.com
Tue Jan 8 22:15:56 CET 2008
Hey all,
Is there a way to make impersonation follow threads? Given this simple
example:
import win32api
import win32security
import win32con
from threading import Thread
class Test(Thread):
def run(self):
print "Username (in thread): ", win32api.GetUserName()
print "Username (before impersonate): ", win32api.GetUserName()
token = win32security.LogonUser('testuser', None, 'testuser', \
win32con.LOGON32_LOGON_INTERACTIVE,
win32con.LOGON32_PROVIDER_DEFAULT)
win32security.ImpersonateLoggedOnUser(token)
print "Username (after impersonate): ", win32api.GetUserName()
Test().start()
print "Username (after thread): ", win32api.GetUserName()
The output will be something like:
Username (before impersonate): Administrator
Username (after impersonate): testuser
Username (after thread): testuser
Username (in thread): Administrator
Thanks
-Matt
More information about the python-win32
mailing list