[python-win32] ImpersonateUser and os.popen4
d.w. harks
dave at psys.org
Thu Feb 19 18:40:54 EST 2004
Greetings, fellow Pythonistas.
I'm working with someone on an installer program which needs to call a
Windows process as a different user. So I went about discovering the
ImpersonateUser calls, and have some code like this:
def Logon(self):
self.mHandle = win32security.LogonUser(self.mUser,self.mDomain,self.mPassword,win32con.LOGON32_LOGON_INTERACTIVE,win32con.LOGON32_PROVIDER_DEFAULT)
win32security.ImpersonateLoggedOnUser(self.mHandle)
So, I execute this, and then go about my tasks as my new user. Fantastic.
If, at this point I call win32api.GetUserName(), I get the impersonated
user, 'installer'.
But if I call an external process, perhaps a short script which just calls
win32api.GetUserName()...
i, o = os.popen4(r"C:\Python23\python.exe C:\\PrintUserName.py")
--> 'harksd'
I've also tried using a WScript.Shell to call the same script, with the same
result.
So, apparently an impersonated user cannot create processes with its own
credentials.
Is there any way to do so? If not, is there any way to create AND DELETE
services using win32all? (the point of this is to call the SC command)
Thanks, I appreciate any pointers you might have.
dave
--
David W. Harks <dave at psys.org> http://dwblog.psys.org
More information about the Python-win32
mailing list