-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawnProc.py
More file actions
81 lines (72 loc) · 2.47 KB
/
SpawnProc.py
File metadata and controls
81 lines (72 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import ctypes
from ctypes.wintypes import HANDLE, DWORD, LPVOID, BOOL, LPSTR, LPBYTE, WORD
k_handle = ctypes.WinDLL("kernel32.dll")
# PROCESS_INFORMATION structure
class PROCESS_INFORMATION(ctypes.Structure):
_field_ = [
("hProcess", HANDLE),
("hThread", HANDLE),
("dwProcessId", DWORD),
("dwThreadId", DWORD)
]
# STARTUPINFOA structure
class STARTUPINFOA(ctypes.Structure):
_field_ = [
("cb", DWORD),
("lpReserved", LPSTR),
("lpDesktop", LPSTR),
("lpTitle", LPSTR),
("dwX", DWORD),
("dwY", DWORD),
("dwXSize", DWORD),
("dwYSize", DWORD),
("dwXCountChars", DWORD),
("dwYCountChars", DWORD),
("dwFillAtribute", DWORD),
("dwFlags", DWORD),
("wShowWindow", WORD),
("cbReserved2", WORD),
("lpReserved2", LPBYTE),
("hStdInput", HANDLE),
("hStdOutput", HANDLE),
("hStdError", HANDLE)
]
'''
BOOL CreateProcessW(
LPCWSTR lpApplicationName,
LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
'''
lpApplicationName = "c:\\Windows\\System32\\cmd.exe" # path to application
lpCommandLine = None
lpProcessAttributes = None
lpThreadAttributes = None
bInheritHandles = False
dwCreationFlags = 0x0010 # CREATE_NEW_CONSOLE
lpEnvironment = None
lpCurrentDirectory = None
lpStartupInfo = ctypes.byref(STARTUPINFOA())
lpProcessInformation = ctypes.byref(PROCESS_INFORMATION())
response = k_handle.CreateProcessW(
lpApplicationName,
lpCommandLine,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
dwCreationFlags,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
lpProcessInformation)
if response != 0:
print("Process is running!!")
else:
print("Create process failed. Error code {}".format(k_handle.GetLastError()))