How to impersonate a user in python and use os.system

I am trying to impersonate a user in python and call the CMD command:

login('secondUser','123')
os.system("some CMD command ")
logout()

where logging in and logging out are functions that are used win32apito impersonate the user.

The problem is that it os.systemdoes not execute the command as an impersonated user ( secondUser), it executes the command when the user logs on to the system.

I am using windows7 64x and python 2.7

Is there a way to invoke a command CMDwith an impersonated user?

+3
source share
1 answer

os.system () is certainly the wrong tool to work with. Try CreateProcess from the win32api module if you use it.

+2
source