Python win32process() Examples
The following are 18
code examples of win32process().
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_helper.py From learn_python3_spider with MIT License | 9 votes |
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()
Example #2
Source File: agent.py From peach with Mozilla Public License 2.0 | 9 votes |
def LaunchWin32Process(self, command): try: StartupInfo = win32process.STARTUPINFO() StartupInfo.dwFlags = win32process.STARTF_USESHOWWINDOW StartupInfo.wShowWindow = win32con.SW_NORMAL win32process.CreateProcess( None, command, None, None, 0, win32process.NORMAL_PRIORITY_CLASS, None, None, StartupInfo) except Exception as e: print(sys.exc_info()) print("Exception in LaunchWin32Process") pass
Example #3
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 #4
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def StartYardServer(self): try: rkey = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Webers\\Y.A.R.D") path = RegQueryValueEx(rkey, "program")[0] if not os.path.exists(path): raise Exception except: raise self.Exception( "Please start Yards.exe first and configure it." ) try: hProcess = CreateProcess( None, path, None, None, 0, CREATE_NEW_CONSOLE, None, None, STARTUPINFO() )[0] except Exception, exc: raise eg.Exception(FormatError(exc[0]))
Example #5
Source File: winpty.py From marsnake with GNU General Public License v3.0 | 6 votes |
def start(self, cmd): sAttr = win32security.SECURITY_ATTRIBUTES() sAttr.bInheritHandle = True stdout_r, stdout_w = win32pipe.CreatePipe(sAttr,0) stdin_r, stdin_w = win32pipe.CreatePipe(sAttr,0) self.read_handle=stdout_r self.write_handle=stdout_w self.stdin_write=stdin_w si = win32process.STARTUPINFO() si.dwFlags = win32process.STARTF_USESHOWWINDOW | win32process.STARTF_USESTDHANDLES si.wShowWindow = win32con.SW_HIDE si.hStdInput = stdin_r # file descriptor of origin stdin si.hStdOutput = stdout_w si.hStdError = stdout_w hProcess, hThread, dwProcessID, dwThreadID = win32process.CreateProcess(None,"cmd", None, None, True, win32process.CREATE_NEW_CONSOLE, None, None, si) self.dwProcessID=dwProcessID self.hProcess=hProcess sleep(0.5) if self.hProcess == 0: DebugOutput("Start Process Fail:{:d}".format(win32api.GetLastError())) DebugOutput('[*] pid: {:x}'.format(self.dwProcessID)) self.Console_hwnd = get_hwnds_for_pid(self.dwProcessID) if len(self.Console_hwnd)==0: raise Exception("Fail to run,No Process!") DebugOutput('[*] hwnd:{:x}'.format(self.Console_hwnd[0]))
Example #6
Source File: process_helper.py From python-for-android with Apache License 2.0 | 6 votes |
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()
Example #7
Source File: mock_win32process.py From learn_python3_spider with MIT License | 5 votes |
def CreateProcess(appName, cmdline, procSecurity, threadSecurity, inheritHandles, newEnvironment, env, workingDir, startupInfo): """ This function mocks the generated pid aspect of the win32.CreateProcess function. - the true win32process.CreateProcess is called - return values are harvested in a tuple. - all return values from createProcess are passed back to the calling function except for the pid, the returned pid is hardcoded to 42 """ hProcess, hThread, dwPid, dwTid = win32process.CreateProcess( appName, cmdline, procSecurity, threadSecurity, inheritHandles, newEnvironment, env, workingDir, startupInfo) dwPid = 42 return (hProcess, hThread, dwPid, dwTid)
Example #8
Source File: shellDev.py From shellDev.py with GNU General Public License v3.0 | 5 votes |
def jitInject(path, shellcode): info = win32process.CreateProcess(None, path, None, None, False, 0x04, None, None, win32process.STARTUPINFO()) page_rwx_value = 0x40 process_all = 0x1F0FFF memcommit = 0x00001000 shellcode_length = len(shellcode) process_handle = info[0].handle # phandle VirtualAllocEx = windll.kernel32.VirtualAllocEx VirtualAllocEx.restype = LPVOID VirtualAllocEx.argtypes = (HANDLE, LPVOID, DWORD, DWORD, DWORD) WriteProcessMemory = ctypes.windll.kernel32.WriteProcessMemory WriteProcessMemory.restype = BOOL WriteProcessMemory.argtypes = (HANDLE, LPVOID, LPCVOID, DWORD, DWORD) CreateRemoteThread = ctypes.windll.kernel32.CreateRemoteThread CreateRemoteThread.restype = HANDLE CreateRemoteThread.argtypes = (HANDLE, LPSECURITY_ATTRIBUTES, DWORD, LPTHREAD_START_ROUTINE, LPVOID, DWORD, DWORD) lpBuffer = VirtualAllocEx(process_handle, 0, shellcode_length, memcommit, page_rwx_value) print(hex(lpBuffer)) WriteProcessMemory(process_handle, lpBuffer, shellcode, shellcode_length, 0) CreateRemoteThread(process_handle, None, 0, lpBuffer, 0, 0, 0) print('JIT Injection, done.') # -------------------------------------------------- #
Example #9
Source File: _dumbwin32proc.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _invalidWin32App(pywinerr): """ Determine if a pywintypes.error is telling us that the given process is 'not a valid win32 application', i.e. not a PE format executable. @param pywinerr: a pywintypes.error instance raised by CreateProcess @return: a boolean """ # Let's do this better in the future, but I have no idea what this error # is; MSDN doesn't mention it, and there is no symbolic constant in # win32process module that represents 193. return pywinerr.args[0] == 193
Example #10
Source File: mock_win32process.py From python-for-android with Apache License 2.0 | 5 votes |
def CreateProcess(appName, cmdline, procSecurity, threadSecurity, inheritHandles, newEnvironment, env, workingDir, startupInfo): """ This function mocks the generated pid aspect of the win32.CreateProcess function. - the true win32process.CreateProcess is called - return values are harvested in a tuple. - all return values from createProcess are passed back to the calling function except for the pid, the returned pid is hardcoded to 42 """ hProcess, hThread, dwPid, dwTid = win32process.CreateProcess( appName, cmdline, procSecurity, threadSecurity, inheritHandles, newEnvironment, env, workingDir, startupInfo) dwPid = 42 return (hProcess, hThread, dwPid, dwTid)
Example #11
Source File: _dumbwin32proc.py From python-for-android with Apache License 2.0 | 5 votes |
def _invalidWin32App(pywinerr): """ Determine if a pywintypes.error is telling us that the given process is 'not a valid win32 application', i.e. not a PE format executable. @param pywinerr: a pywintypes.error instance raised by CreateProcess @return: a boolean """ # Let's do this better in the future, but I have no idea what this error # is; MSDN doesn't mention it, and there is no symbolic constant in # win32process module that represents 193. return pywinerr.args[0] == 193
Example #12
Source File: desktopmanager.py From ironpython2 with Apache License 2.0 | 5 votes |
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()
Example #13
Source File: _dumbwin32proc.py From learn_python3_spider with MIT License | 5 votes |
def _invalidWin32App(pywinerr): """ Determine if a pywintypes.error is telling us that the given process is 'not a valid win32 application', i.e. not a PE format executable. @param pywinerr: a pywintypes.error instance raised by CreateProcess @return: a boolean """ # Let's do this better in the future, but I have no idea what this error # is; MSDN doesn't mention it, and there is no symbolic constant in # win32process module that represents 193. return pywinerr.args[0] == 193
Example #14
Source File: main.py From perfect_video_downloader with MIT License | 5 votes |
def launch_chrome(): global chrome if os.path.exists(chrome_path): command="\"{}\"--remote-debugging-port={}".format(chrome_path, port_chrome) print(u"如果Chrome白屏,请使用CMD手动运行以下命令:\n{}".format(command)) chrome = win32process.CreateProcess(None, "{} --remote-debugging-port={}".format(chrome_path, port_chrome),None, None, 0, 0, None, None, win32process.STARTUPINFO()) else: print(u"未找到Chrome安装目录") exit(-1)
Example #15
Source File: mock_win32process.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def CreateProcess(appName, cmdline, procSecurity, threadSecurity, inheritHandles, newEnvironment, env, workingDir, startupInfo): """ This function mocks the generated pid aspect of the win32.CreateProcess function. - the true win32process.CreateProcess is called - return values are harvested in a tuple. - all return values from createProcess are passed back to the calling function except for the pid, the returned pid is hardcoded to 42 """ hProcess, hThread, dwPid, dwTid = win32process.CreateProcess( appName, cmdline, procSecurity, threadSecurity, inheritHandles, newEnvironment, env, workingDir, startupInfo) dwPid = 42 return (hProcess, hThread, dwPid, dwTid)
Example #16
Source File: process_helper.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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()
Example #17
Source File: _dumbwin32proc.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def _invalidWin32App(pywinerr): """ Determine if a pywintypes.error is telling us that the given process is 'not a valid win32 application', i.e. not a PE format executable. @param pywinerr: a pywintypes.error instance raised by CreateProcess @return: a boolean """ # Let's do this better in the future, but I have no idea what this error # is; MSDN doesn't mention it, and there is no symbolic constant in # win32process module that represents 193. return pywinerr.args[0] == 193
Example #18
Source File: test_win32trace.py From ironpython2 with Apache License 2.0 | 5 votes |
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