A detailed example of the python system call

  • 2020-06-12 09:32:13
  • OfStack

A detailed example of the python system call

This article covers python system calls in two ways, including python using CreateProcess functions to run other programs and instances of ctypes modules,

python USES the CreateProcess function to run other programs


>>> import win32process 
>>> handle = win32process.CreateProcess('c:\\windows\\notepad.exe','',None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO()) 
>>> win32process.TerminateProcess(handle[0],0) 
>>> import win32event 
>>> handle = win32process.CreateProcess('c:\\windows\\notepad.exe','',None,None,0,win32process.CREATE_NO_WINDOW,None,None,win32process.STARTUPINFO()) 
>>> win32event.WaitForSingleObject(handle[0],-1) 
0 
 

2 Introduction to ctypes module

The following code calls the MessageBoxA function in ES23en32.dll directly under windows using the ctype module.


>>> from ctypes import * 
>>> user32 = windll.LoadLibrary('user32.dll') 
>>> user32.MessageBoxA(0,str.encode('Ctype is cool!'),str.encode('Ctype'),0) 
1 

Thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: