尝试这个:
import sys, os.path, ctypes, ctypes.wintypesPsapi = ctypes.WinDLL('Psapi.dll')EnumProcesses = Psapi.EnumProcessesEnumProcesses.restype = ctypes.wintypes.BOOLGetProcessImageFileName = Psapi.GetProcessImageFileNameAGetProcessImageFileName.restype = ctypes.wintypes.DWORDKernel32 = ctypes.WinDLL('kernel32.dll')OpenProcess = Kernel32.OpenProcessOpenProcess.restype = ctypes.wintypes.HANDLETerminateProcess = Kernel32.TerminateProcessTerminateProcess.restype = ctypes.wintypes.BOOLCloseHandle = Kernel32.CloseHandleMAX_PATH = 260PROCESS_TERMINATE = 0x0001PROCESS_QUERY_INFORMATION = 0x0400count = 32while True: ProcessIds = (ctypes.wintypes.DWORD*count)() cb = ctypes.sizeof(ProcessIds) BytesReturned = ctypes.wintypes.DWORd() if EnumProcesses(ctypes.byref(ProcessIds), cb, ctypes.byref(BytesReturned)): if BytesReturned.value<cb: break else: count *= 2 else: sys.exit("Call to EnumProcesses failed")for index in range(BytesReturned.value / ctypes.sizeof(ctypes.wintypes.DWORD)): ProcessId = ProcessIds[index] hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, False, ProcessId) if hProcess: ImageFileName = (ctypes.c_char*MAX_PATH)() if GetProcessImageFileName(hProcess, ImageFileName, MAX_PATH)>0: filename = os.path.basename(ImageFileName.value) if filename == 'notepad.exe': TerminateProcess(hProcess, 1) CloseHandle(hProcess)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)