[python-win32] Is there a Python win32 RunAs equivalent where youcan send a password?

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Mon Mar 15 15:45:36 EST 2004


> -----Original Message-----
> I need to spawn a commandline program from within my Python 
> script multiple times. Each time it's spawned it needs to run 
> under a different account from a different domain. As best I 
> can tell, I can't spawn a cmd file and use the normal "runas" 
> command provided in windows because it prompts for the 
> password, and I need my script to run unattended. Any suggestions?
> 
> I glanced at win32process.CreateProcessAsUser, but it didn't 
> appear to have an argument to in which I could send the password.
> 

Have a look at win32security.LogonUser and
win32security.ImpersonateLoggedOnUser.  There is a nice example in the
Python Cookbook (print edition only, I think?) on page 257.  I have also
used a COM object called sfImpersonator to some success.  You probably
*could* spawn a cmd file and use popen to send the password, but it
would have to be a hack.

Christian
http://www.dowski.com



More information about the Python-win32 mailing list