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

R. Alan Monroe amonroe at columbus.rr.com
Thu Mar 18 09:30:27 EST 2004


> Look at the comments in the recipe - the full text is at
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81402/

> Basically, you need special rights to do this "Act as part of the
> Operating System" is the key bit. The "RunAs" command gets round this
> by using a service as an intermediary. The "RunAs" service handles the
> job of running as a different user - it runs as the SYSTEM user, which
> has most rights on by default.


Does this whole impersonation business work with os.system()? What
about the threading module? I'm not having any luck with it.

Per the cookbook site I got this to run:


try:
    a.logon()
    print win32api.GetUserName()
    os.system("notepad")
    a.logoff()
except:
    print sys.exc_type, sys.exc_value


the print win32api.GetUserName() prints the impersonated user's name
like I expect, but the notepad process is running as _me_, not the
impersonated user (@&$#^@$!!!). Am I doing something wrong?

I briefly toyed with win32process.CreateProcessAsUser, but that put me
back at square one with the error about not having a required
privilege.

Alan




More information about the Python-win32 mailing list