zoukankan      html  css  js  c++  java
  • windows下查看所有进程以及pid

    import ctypes
    import sys
    __metaclass__ = type
    
    class PROCESSENTRY32(ctypes.Structure):
        _fields_ = [
            ("dwSize",ctypes.c_ulong),
            ("cntUsage",ctypes.c_ulong),
            ("th32ProcessID",ctypes.c_ulong),
            ("th32DefaultHeapID",ctypes.c_void_p),
            ("th32ModuleID",ctypes.c_ulong),
            ("cntThreads",ctypes.c_ulong),
            ("th32ParentProcessID",ctypes.c_ulong),
            ("pcPriClassBase",ctypes.c_long),
            ("dwFlags",ctypes.c_ulong),
            ("szExeFile",ctypes.c_char*260)
        ]
    def process():
        kernel32 = ctypes.windll.LoadLibrary("kernel32.dll")
        pHandle = kernel32.CreateToolhelp32Snapshot(0x2,0x0)
        if pHandle == -1:
            sys.exit()
        proc = PROCESSENTRY32()
        proc.dwSize = ctypes.sizeof(proc)
        while kernel32.Process32Next(pHandle,ctypes.byref(proc)):
            print("%d-%s"%(proc.th32ProcessID,ctypes.string_at(proc.szExeFile)))
        kernel32.CloseHandle(pHandle)
       
    if __name__ == '__main__':
        process()
  • 相关阅读:
    linux-常用命令
    linux
    测试基础
    链家笔试1
    链家笔试2
    链家笔试3
    MySql优化
    Http1.1和Http2.0
    Charles学习
    链表中倒数第k个结点
  • 原文地址:https://www.cnblogs.com/huangxiaohen/p/3373352.html
Copyright © 2011-2022 走看看