Python win32process.GetExitCodeProcess() Examples
The following are 19
code examples of win32process.GetExitCodeProcess().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32process
, or try the search function
.
Example #1
Source File: process.py From peach with Mozilla Public License 2.0 | 7 votes |
def call(self, method, args): """ Launch program to consume file @type method: string @param method: Command to execute @type args: array of objects @param args: Arguments to pass """ hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess( None, self.commandLine, None, None, 0, win32con.NORMAL_PRIORITY_CLASS, None, None, None) while win32process.GetExitCodeProcess(hProcess) == win32con.STILL_ACTIVE: time.sleep(0.25) self.closeApp(hProcess, self._windowName)
Example #2
Source File: admin.py From uac-a-mola with GNU General Public License v3.0 | 6 votes |
def runAsAdmin(cmdLine=None, wait=True): if os.name != 'nt': raise RuntimeError, "This function is only implemented on Windows." import win32api import win32con import win32event import win32process from win32com.shell.shell import ShellExecuteEx from win32com.shell import shellcon python_exe = sys.executable if cmdLine is None: cmdLine = [python_exe] + sys.argv elif type(cmdLine) not in (types.TupleType, types.ListType): raise ValueError, "cmdLine is not a sequence." cmd = '"%s"' % (cmdLine[0],) # XXX TODO: isn't there a function or something we can call to massage command line params? params = " ".join(['"%s"' % (x,) for x in cmdLine[1:]]) cmdDir = '' #showCmd = win32con.SW_SHOWNORMAL showCmd = win32con.SW_HIDE lpVerb = 'runas' # causes UAC elevation prompt. # print "Running", cmd, params # ShellExecute() doesn't seem to allow us to fetch the PID or handle # of the process, so we can't get anything useful from it. Therefore # the more complex ShellExecuteEx() must be used. # procHandle = win32api.ShellExecute(0, lpVerb, cmd, params, cmdDir, showCmd) procInfo = ShellExecuteEx(nShow=showCmd, fMask=shellcon.SEE_MASK_NOCLOSEPROCESS, lpVerb=lpVerb, lpFile=cmd, lpParameters=params) if wait: procHandle = procInfo['hProcess'] obj = win32event.WaitForSingleObject(procHandle, win32event.INFINITE) rc = win32process.GetExitCodeProcess(procHandle) # print "Process handle %s returned code %s" % (procHandle, rc) else: rc = None return rc
Example #3
Source File: _dumbwin32proc.py From learn_python3_spider with MIT License | 5 votes |
def checkWork(self): if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0: return 0 exitCode = win32process.GetExitCodeProcess(self.proc.hProcess) self.deactivate() self.proc.processEnded(exitCode) return 0
Example #4
Source File: test_windows.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_wait(self): handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, win32con.FALSE, self.pid) self.addCleanup(win32api.CloseHandle, handle) p = psutil.Process(self.pid) p.terminate() psutil_value = p.wait() sys_value = win32process.GetExitCodeProcess(handle) self.assertEqual(psutil_value, sys_value)
Example #5
Source File: process.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def connectionLost(self, reason=None): """Shut down resources.""" # Get the exit status and notify the protocol exitCode = win32process.GetExitCodeProcess(self.hProcess) if exitCode == 0: err = error.ProcessDone(exitCode) else: err = error.ProcessTerminated(exitCode) self.protocol.processEnded(failure.Failure(err)) ## IConsumer
Example #6
Source File: _dumbwin32proc.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def checkWork(self): if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0: return 0 exitCode = win32process.GetExitCodeProcess(self.proc.hProcess) if exitCode == 0: err = error.ProcessDone(exitCode) else: err = error.ProcessTerminated(exitCode) self.deactivate() self.proc.protocol.processEnded(failure.Failure(err)) return 0
Example #7
Source File: _dumbwin32proc.py From python-for-android with Apache License 2.0 | 5 votes |
def checkWork(self): if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0: return 0 exitCode = win32process.GetExitCodeProcess(self.proc.hProcess) self.deactivate() self.proc.processEnded(exitCode) return 0
Example #8
Source File: tcp.py From peach with Mozilla Public License 2.0 | 5 votes |
def enumCallback(hwnd, windowName): """ Will get called by win32gui.EnumWindows, once for each top level application window. """ try: # Get window title title = win32gui.GetWindowText(hwnd) # Is this our guy? if title.find(windowName) == -1: return (threadId, processId) = win32process.GetWindowThreadProcessId(hwnd) # Send WM_CLOSE message try: win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) win32gui.PostQuitMessage(hwnd) except: pass # Give it upto 5 sec for i in range(100): if win32process.GetExitCodeProcess(processId) != win32con.STILL_ACTIVE: # Process exited already return time.sleep(0.25) try: # Kill application win32process.TerminateProcess(processId, 0) except: pass except: pass
Example #9
Source File: platform_windows.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def _run_as_administrators(self, executable, arguments): """Invokes the specified executable with the specified arguments, escalating the privileges of the process to Administrators. All output that process generates to stdout/stderr will be echoed to this process's stdout/stderr. Note, this can only be used on executables that accept the `--redirect-to-pipe` option to allow for this process to capture the output from the escalated process. Note, Windows will ask for confirmation and/or an Administrator password before the process is escalated. @param executable: The path to the Windows executable to run escalated. @param arguments: An array of arguments to supply to the executable. @type executable: str @type arguments: [] @return: The exit code of the process. @rtype: int """ client = PipeRedirectorClient() arguments = arguments + ["--redirect-to-pipe", client.pipe_name] child_process = win32com.shell.shell.ShellExecuteEx( fMask=256 + 64, lpVerb="runas", lpFile=executable, lpParameters=" ".join(arguments), ) client.start() proc_handle = child_process["hProcess"] win32event.WaitForSingleObject(proc_handle, -1) client.stop() return win32process.GetExitCodeProcess(proc_handle)
Example #10
Source File: winprocess.py From ironpython2 with Apache License 2.0 | 5 votes |
def exitCode(self): """ Return process exit code. """ return win32process.GetExitCodeProcess(self.hProcess)
Example #11
Source File: winpty.py From marsnake with GNU General Public License v3.0 | 5 votes |
def isalive(self): return win32process.GetExitCodeProcess(self.hProcess) == win32con.STILL_ACTIVE
Example #12
Source File: WindowsServer.py From pycopia with Apache License 2.0 | 5 votes |
def alive(self): es = win32process.GetExitCodeProcess(self.handle) if es == win32con.STILL_ACTIVE: return True else: return False # wait until finished
Example #13
Source File: WindowsServer.py From pycopia with Apache License 2.0 | 5 votes |
def poll(self): es = win32process.GetExitCodeProcess(self.handle) if es == win32con.STILL_ACTIVE: return None else: self.exitstatus = ExitStatus(self.cmdline, es) self.dead() return self.exitstatus # called when process determined to be daed
Example #14
Source File: WindowsServer.py From pycopia with Apache License 2.0 | 5 votes |
def close(self): if win32process.GetExitCodeProcess(self.handle) == win32con.STILL_ACTIVE: self.kill() self.child_stdin.close() self.child_stdin = None if self.child_stderr: self.child_stdin.close() self.child_stdin = None es = ExitStatus(self.cmdline, self.child_stdout.close()) if self.exitstatus is None: self.exitstatus = es self.child_stdout = None self.dead() return self.exitstatus
Example #15
Source File: _dumbwin32proc.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def checkWork(self): if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0: return 0 exitCode = win32process.GetExitCodeProcess(self.proc.hProcess) self.deactivate() self.proc.processEnded(exitCode) return 0
Example #16
Source File: test_windows.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_wait(self): handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, win32con.FALSE, self.pid) self.addCleanup(win32api.CloseHandle, handle) p = psutil.Process(self.pid) p.terminate() psutil_value = p.wait() sys_value = win32process.GetExitCodeProcess(handle) self.assertEqual(psutil_value, sys_value)
Example #17
Source File: test_windows.py From vnpy_crypto with MIT License | 5 votes |
def test_wait(self): handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, win32con.FALSE, self.pid) self.addCleanup(win32api.CloseHandle, handle) p = psutil.Process(self.pid) p.terminate() psutil_value = p.wait() sys_value = win32process.GetExitCodeProcess(handle) self.assertEqual(psutil_value, sys_value)
Example #18
Source File: test_win32trace.py From ironpython2 with Apache License 2.0 | 5 votes |
def join(self): win32event.WaitForSingleObject(self.processHandle, win32event.INFINITE) self.exitCode = win32process.GetExitCodeProcess(self.processHandle)
Example #19
Source File: process.py From peach with Mozilla Public License 2.0 | 4 votes |
def callWindows(self): """ Launch program to consume file """ # Launch via spawn realArgs = ["cmd.exe", "/c", self.command] for a in self.args: realArgs.append(a) phandle = os.spawnv(os.P_NOWAIT, os.path.join(os.getenv('SystemRoot'), 'system32', 'cmd.exe'), realArgs) # Give it some time before we KILL! for i in range(int(self.waitTime / 0.25)): if win32process.GetExitCodeProcess(phandle) != win32con.STILL_ACTIVE: # Process exited already break time.sleep(0.25) try: pid = ctypes.windll.kernel32.GetProcessId(ctypes.c_ulong(phandle)) if pid > 0: for cid in self.FindChildrenOf(pid): chandle = win32api.OpenProcess(1, 0, cid) win32process.TerminateProcess(chandle, 0) try: win32api.CloseHandle(chandle) except: pass win32process.TerminateProcess(phandle, 0) try: win32api.CloseHandle(phandle) except: pass except: pass