CreateProcessAsUser done! How to control the created process?

落花浮王杯 提交于 2019-12-11 10:10:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!