[python-win32] Query on - win32 impersonate user

Vikas NV vikas.nv at gmail.com
Mon Jun 8 09:55:08 CEST 2009


Hi,

I have been trying to use the Impersonate user code that you have in
the PyWin32.chm document.
The code that I am trying is :
import win32security
import win32con
import win32api

class Impersonate:
    def __init__(self,login,password):
        self.domain='BLAHBLAH'
        self.login=login
        self.password=password
    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

if __name__ == '__main__':
    import os
    import sys
    sys.stdout.write ('Start process as ')
    obj = Impersonate('another_user', '01928348')
    obj.logon()
    print win32api.GetUserName()
    os.system('bash sleep.sh')
    obj.logoff()

The sleep.sh this script uses has these commands "touch file1; sleep
300"

I am running this on Windows XP and with MKS toolkit installed on it
(so i can use 'bash', as in the code). I am currently logged in as
Vikas.

So when I see the task manager while the python script runs, the
sleep.sh is invoked as user 'Vikas' instead as 'another_user'.
And also the file that sleep.sh touches 'file1' has owner as 'Vikas'
instead of 'another_user'
So my query is that why is sleep.sh run as Vikas even though I
impersonate as 'another_user' ? Following the question, why is the
owner of file1 is 'Vikas' instead of 'another_user' ?

-- 
Vikas N V
mob: 9900107434
Visit my BLOG: http://techdiary-viki.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090608/cee95356/attachment.htm>


More information about the python-win32 mailing list