问题
I'm trying to launch an app as another user, this works perfectly, the process is created, but I don't know how to handle the created process as I usually do with comtypes or win32com (COM interface), here is the script:
import win32process
import win32security
import win32con
import cgi
import cgitb; cgitb.enable()
domain = '.'
username = 'me'
password = 'mypwd'
try:
token = win32security.LogonUser (
username,
domain,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT
)
except win32security.error:
print "Failed"
else:
appname = "C:/path/to/app.exe"
startup = win32process.STARTUPINFO()
priority = win32con.NORMAL_PRIORITY_CLASS
handle, thread_id ,pid, tid = win32process.CreateProcessAsUser(token, appname, None, None, None, True, priority, None, None, startup)
Usually, when I don't need to run the process as another user, I use (for example with win32com):
import win32com.client
app = win32com.client.Dispatch("app.Application")
Then I can control the application with the app
object
Being the same library, I guess I can do something with handle
or thread_id
together with win32com.client
keeping the same user, but I don't found anything, can you please help me.
来源:https://stackoverflow.com/questions/29242343/createprocessasuser-done-how-to-control-the-created-process