Python win32process 模块,STARTUPINFO 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用win32process.STARTUPINFO

项目:aquests    作者:hansroh    | 项目源码 | 文件源码
def execute (cmd, timeout = 0):
        if timeout == 0:
            timeout = win32event.INFINITE

        info  = win32process.CreateProcess(None, cmd, None, None, 0, 0, None, None, win32process.STARTUPINFO())
        subprocess = info [0]

        rc = win32event.WaitForSingleObject (subprocess, timeout)           

        if rc == win32event.WAIT_FAILED:    
            return -1

        if rc == win32event.WAIT_TIMEOUT:
            try:
                win32process.TerminateProcess (subprocess, 0)                   
            except pywintypes.error:
                return -3
            return -2

        if rc == win32event.WAIT_OBJECT_0:
            return win32process.GetExitCodeProcess(subprocess)
项目:aquests    作者:hansroh    | 项目源码 | 文件源码
def timeout_execute (cmd, timeout = 0):
        if timeout == 0:
            timeout = win32event.INFINITE

        info  = win32process.CreateProcess(None, cmd, None, None, 0, 0, None, None, win32process.STARTUPINFO())
        subprocess = info [0]

        rc = win32event.WaitForSingleObject (subprocess, timeout)           

        if rc == win32event.WAIT_FAILED:    
            return -1

        if rc == win32event.WAIT_TIMEOUT:
            try:
                win32process.TerminateProcess (subprocess, 0)                   
            except pywintypes.error:
                return -3
            return -2

        if rc == win32event.WAIT_OBJECT_0:
            return win32process.GetExitCodeProcess(subprocess)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def create_desktop(desktop_name, start_explorer=1):
    """ Creates a new desktop and spawns a thread running on it
        Will also start a new icon thread on an existing desktop
    """
    sa=pywintypes.SECURITY_ATTRIBUTES()
    sa.bInheritHandle=1

    try:
        hdesk=win32service.CreateDesktop(desktop_name, 0, win32con.MAXIMUM_ALLOWED, sa)
    except win32service.error:
        traceback.print_exc()
        errbuf=cStringIO.StringIO()
        traceback.print_exc(None,errbuf)
        win32api.MessageBox(0, errbuf.getvalue(), 'Desktop creation failed')
        return
    if start_explorer:
        s=win32process.STARTUPINFO()
        s.lpDesktop=desktop_name
        prc_info=win32process.CreateProcess(None, "Explorer.exe",None,None,True,win32con.CREATE_NEW_CONSOLE,None,'c:\\',s)

    th=thread.start_new_thread(new_icon,(hdesk,desktop_name))
    hdesk.SwitchDesktop()
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def create_desktop(desktop_name, start_explorer=1):
    """ Creates a new desktop and spawns a thread running on it
        Will also start a new icon thread on an existing desktop
    """
    sa=pywintypes.SECURITY_ATTRIBUTES()
    sa.bInheritHandle=1

    try:
        hdesk=win32service.CreateDesktop(desktop_name, 0, win32con.MAXIMUM_ALLOWED, sa)
    except win32service.error:
        traceback.print_exc()
        errbuf=io.StringIO()
        traceback.print_exc(None,errbuf)
        win32api.MessageBox(0, errbuf.getvalue(), 'Desktop creation failed')
        return
    if start_explorer:
        s=win32process.STARTUPINFO()
        s.lpDesktop=desktop_name
        prc_info=win32process.CreateProcess(None, "Explorer.exe",None,None,True,win32con.CREATE_NEW_CONSOLE,None,'c:\\',s)

    th=_thread.start_new_thread(new_icon,(hdesk,desktop_name))
    hdesk.SwitchDesktop()
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def main():
    if sys.argv[1] == 'child':
        if sys.argv[2] == 'windows':
            import win32api as api, win32process as proc
            info = proc.STARTUPINFO()
            info.hStdInput = api.GetStdHandle(api.STD_INPUT_HANDLE)
            info.hStdOutput = api.GetStdHandle(api.STD_OUTPUT_HANDLE)
            info.hStdError = api.GetStdHandle(api.STD_ERROR_HANDLE)
            python = sys.executable
            scriptDir = os.path.dirname(__file__)
            scriptName = os.path.basename(__file__)
            proc.CreateProcess(
                None, " ".join((python, scriptName, "grandchild")), None,
                None, 1, 0, os.environ, scriptDir, info)
        else:
            if os.fork() == 0:
                grandchild()
    else:
        grandchild()
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
def Open_TDX():
    try:
        handle = win32process.CreateProcess(path+'TdxW.exe','',None,None,0,win32process.CREATE_NO_WINDOW,None,path,win32process.STARTUPINFO())#??TB,?????
        time.sleep(3)
        TDX_handle = win32gui.FindWindow('#32770','???????V7.35')
    except Exception as e:
        ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))

#????
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def start(self):
        procHandle, threadHandle, procId, threadId  = win32process.CreateProcess(
            None, # appName
            'python.exe "%s" /run_test_process %s %s' % (this_file,
                                                         self.BucketCount,
                                                         self.threadCount),
            None, # process security
            None, # thread security
            0, # inherit handles
            win32process.NORMAL_PRIORITY_CLASS,
            None, # new environment
            None, # Current directory
            win32process.STARTUPINFO(), # startup info
            )
        self.processHandle = procHandle
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def start(self):
        procHandle, threadHandle, procId, threadId  = win32process.CreateProcess(
            None, # appName
            'python.exe "%s" /run_test_process %s %s' % (this_file,
                                                         self.BucketCount,
                                                         self.threadCount),
            None, # process security
            None, # thread security
            0, # inherit handles
            win32process.NORMAL_PRIORITY_CLASS,
            None, # new environment
            None, # Current directory
            win32process.STARTUPINFO(), # startup info
            )
        self.processHandle = procHandle
项目:viewvc    作者:viewvc    | 项目源码 | 文件源码
def CreateProcess(cmd, hStdInput, hStdOutput, hStdError):
  """Creates a new process which uses the specified handles for its standard
  input, output, and error. The handles must be inheritable. 0 can be passed
  as a special handle indicating that the process should inherit the current
  process's input, output, or error streams, and None can be passed to discard
  the child process's output or to prevent it from reading any input."""

  # initialize new process's startup info
  si = win32process.STARTUPINFO()
  si.dwFlags = win32process.STARTF_USESTDHANDLES

  if hStdInput == 0:
    si.hStdInput = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)
  else:
    si.hStdInput = hStdInput

  if hStdOutput == 0:
    si.hStdOutput = win32api.GetStdHandle(win32api.STD_OUTPUT_HANDLE)
  else:
    si.hStdOutput = hStdOutput

  if hStdError == 0:
    si.hStdError = win32api.GetStdHandle(win32api.STD_ERROR_HANDLE)
  else:
    si.hStdError = hStdError

  # create the process
  phandle, pid, thandle, tid = win32process.CreateProcess \
  ( None,                            # appName
    cmd,                             # commandLine
    None,                            # processAttributes
    None,                            # threadAttributes
    1,                               # bInheritHandles
    win32con.NORMAL_PRIORITY_CLASS,  # dwCreationFlags
    None,                            # newEnvironment
    None,                            # currentDirectory
    si                               # startupinfo
  )

  if hStdInput and hasattr(hStdInput, 'Close'):
    hStdInput.Close()

  if hStdOutput and hasattr(hStdOutput, 'Close'):
    hStdOutput.Close()

  if hStdError and hasattr(hStdError, 'Close'):
    hStdError.Close()

  return phandle, pid, thandle, tid
项目:Project-Console-Game-Localization    作者:wmltogether    | 项目源码 | 文件源码
def runExec(filename):
    handle = win32process.CreateProcess(u'yaz0enc.exe',' %s'%(r'"'+filename+r'"'),\
                                                    None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO())
    win32event.WaitForSingleObject(handle[0], -1)
项目:Project-Console-Game-Localization    作者:wmltogether    | 项目源码 | 文件源码
def runTexconv(filename):
    handle = win32process.CreateProcess(u'TexConv2.exe','-i %s -o \"tmp\\tmp.dds\"'%(r'"'+filename+r'"'),\
                                                    None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO())
    win32event.WaitForSingleObject(handle[0], -1)
项目:Project-Console-Game-Localization    作者:wmltogether    | 项目源码 | 文件源码
def runDDS2PNG(filename ,format_name):
    if format_name == "RGBA8888":
        dds_name = r'"'+filename+r'"'
        png_name = r'"'+filename[:-4] + '.png'+r'"'
        handle = win32process.CreateProcess(u'AMDCompressCLI.exe',' %s %s'%(dds_name , png_name),\
                                                    None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO())
        win32event.WaitForSingleObject(handle[0], -1)
    else:

        handle = win32process.CreateProcess(u'nvdecompress.exe',' %s'%(r'"'+filename+r'"'),\
                                                    None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO())
        win32event.WaitForSingleObject(handle[0], -1)
项目:Project-Console-Game-Localization    作者:wmltogether    | 项目源码 | 文件源码
def runTexconv(dds_name ,gtx_name , swizzle):
    handle = win32process.CreateProcess(u'TexConv2.exe', ' -i \"%s\" -o \"%s\" -swizzle %d'%(dds_name , gtx_name , swizzle),\
                                                    None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO())
    win32event.WaitForSingleObject(handle[0], -1)
项目:Project-Console-Game-Localization    作者:wmltogether    | 项目源码 | 文件源码
def runPNG2DDS(format_name ,png_name , dds_name):
    if ".tga" in png_name:
        print('nvcompress.exe -nomips %s \"%s\" \"%s\"'%(format_dict[format_name] , png_name , dds_name))
        handle = win32process.CreateProcess(u'nvcompress.exe',' -nomips %s \"%s\" \"%s\"'%(format_dict[format_name] , png_name , dds_name),\
                                                    None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO())
        win32event.WaitForSingleObject(handle[0], -1)
    else:
        print('AMDCompressCLI.exe -fd %s \"%s\" \"%s\"'%(format_name , png_name , dds_name))
        handle = win32process.CreateProcess(u'AMDCompressCLI.exe',' -fd %s \"%s\" \"%s\"'%("ARGB8888" , png_name , dds_name),\
                                                    None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO())
        win32event.WaitForSingleObject(handle[0], -1)
项目:autoops_for_win    作者:qiueer    | 项目源码 | 文件源码
def CreateProc(cls, exepath, paramstr="", cwd=None):
        exepath = u"%s" % (exepath)
        pos = exepath.rfind('\\')
        cwd = cwd if cwd else exepath[0:pos]
        (proc_hd, thread_hd,  proc_id, thread_id) =  win32process.CreateProcess(exepath, paramstr, None, None, 0, win32process.CREATE_NO_WINDOW,   
        None, cwd, win32process.STARTUPINFO())
        return (proc_hd, thread_hd,  proc_id, thread_id)
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def do_createprocess_exe(self,FILEPATH=None):
        if FILEPATH==None:
            FILEPATH = self.filepath
        exe_path = os.path.dirname(FILEPATH)
        exe_file = FILEPATH.split('\\')[-1]
        os.chdir(exe_path)
        try:
            handle = win32process.CreateProcess(
                os.path.join(exe_path, exe_file),
                '', None, None, 0,
                win32process.CREATE_NO_WINDOW,
                None ,
                exe_path,
                win32process.STARTUPINFO())
            self.running = True

        except Exception, e:
            print "Create Error!"
            handle  = None
            self.running = False
        '''    
        while self.running :
            rc = win32event.WaitForSingleObject(handle[0], 1000)
            if rc == win32event.WAIT_OBJECT_0:
                self.running = False
        '''
        print "GoodBye"