1 #Copyright (c) 2008 Vincent Povirk
3 #Permission is hereby granted, free of charge, to any person
4 #obtaining a copy of this software and associated documentation
5 #files (the "Software"), to deal in the Software without
6 #restriction, including without limitation the rights to use,
7 #copy, modify, merge, publish, distribute, sublicense, and/or sell
8 #copies of the Software, and to permit persons to whom the
9 #Software is furnished to do so, subject to the following
12 #The above copyright notice and this permission notice shall be
13 #included in all copies or substantial portions of the Software.
15 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 #OTHER DEALINGS IN THE SOFTWARE.
24 #Process creation/manipulation
26 from ctypes
import windll
, Structure
, POINTER
, byref
27 from winlitecfg
import get_aw_symbols
28 from winliteutils
import get_symbols
, NONZERO
29 from windef
import LPCTSTR
, LPTSTR
, BOOL
, DWORD
, LPVOID
, WORD
, LPBYTE
, HANDLE
, LPDWORD
31 DEBUG_PROCESS
= 0x00000001
32 DEBUG_ONLY_THIS_PROCESS
= 0x00000002
33 CREATE_SUSPENDED
= 0x00000004
34 DETACHED_PROCESS
= 0x00000008
35 CREATE_NEW_CONSOLE
= 0x00000010
36 CREATE_NEW_PROCESS_GROUP
= 0x00000200
37 CREATE_UNICODE_ENVIRONMENT
= 0x00000400
38 CREATE_SEPARATE_WOW_VDM
= 0x00000800
39 CREATE_SHARED_WOW_VDM
= 0x00001000
40 INHERIT_PARENT_AFFINITY
= 0x00010000
41 CREATE_PROTECTED_PROCESS
= 0x00040000
42 EXTENDED_STARTUPINFO_PRESENT
= 0x00080000
43 CREATE_BREAKAWAY_FROM_JOB
= 0x01000000
44 CREATE_PRESERVE_CODE_AUTHZ_LEVEL
= 0x02000000
45 CREATE_DEFAULT_ERROR_MODE
= 0x04000000
46 CREATE_NO_WINDOW
= 0x08000000
48 class SECURITY_ATTRIBUTES(Structure
):
51 ("lpSecurityDescriptor", LPVOID
),
52 ("bInheritHandle", BOOL
),
54 PSECURITY_ATTRIBUTES
= LPSECURITY_ATTRIBUTES
= POINTER(SECURITY_ATTRIBUTES
)
56 class STARTUPINFO(Structure
):
59 ('lpReserved', LPTSTR
),
60 ('lpDesktop', LPTSTR
),
65 ('dwXCountChars', DWORD
),
66 ('dwYCountChars', DWORD
),
67 ('dwFillAttribute', DWORD
),
69 ('wShowWindow', WORD
),
70 ('cbReserved2', WORD
),
71 ('lpReserved2', LPBYTE
),
72 ('hStdInput', HANDLE
),
73 ('hStdOutput', HANDLE
),
74 ('hStdError', HANDLE
),
76 LPSTARTUPINFO
= POINTER(STARTUPINFO
)
78 PPROC_THREAD_ATTRIBUTE_LIST
= LPPROC_THREAD_ATTRIBUTE_LIST
= LPVOID
80 class STARTUPINFOEX(STARTUPINFO
):
82 ('StartupInfo', STARTUPINFO
),
83 ('lpAttributeList', PPROC_THREAD_ATTRIBUTE_LIST
),
86 class PROCESS_INFORMATION(Structure
):
90 ('dwProcessId', DWORD
),
91 ('dwThreadId', DWORD
),
93 LPPROCESS_INFORMATION
= POINTER(PROCESS_INFORMATION
)
95 get_aw_symbols(globals(), windll
.kernel32
, ['CreateProcess'])
97 CreateProcess
.argtypes
= [LPCTSTR
, LPTSTR
, LPSECURITY_ATTRIBUTES
, LPSECURITY_ATTRIBUTES
, BOOL
, DWORD
, LPVOID
, LPCTSTR
, LPSTARTUPINFO
, LPPROCESS_INFORMATION
]
98 CreateProcess
.restype
= NONZERO
100 get_symbols(globals(), windll
.kernel32
, ['GetExitCodeProcess'])
102 GetExitCodeProcess
.argtypes
= [HANDLE
, LPDWORD
]
103 GetExitCodeProcess
.restype
= NONZERO
104 _GetExitCodeProcess
= GetExitCodeProcess
105 def GetExitCodeProcess(handle
):
107 _GetExitCodeProcess(handle
, byref(result
))