返回顶部

收藏

window下调用api列出当前所有进程

更多
#!/usr/bin/env python
#-*- coding:utf-8 -*-

"通过调用API获取进程列表"

import ctypes;

__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)
    ]

kernel32 = ctypes.windll.LoadLibrary("kernel32.dll");
pHandle = kernel32.CreateToolhelp32Snapshot(0x2,0x0);

import sys;

if pHandle==-1:
    sys.exit();

proc = PROCESSENTRY32();
proc.dwSize = ctypes.sizeof(proc);

while kernel32.Process32Next(pHandle,ctypes.byref(proc)):
    print("ProcessName : %s - ProcessID : %d"%(ctypes.string_at(proc.szExeFile),proc.th32ProcessID));

kernel32.CloseHandle(pHandle);
#该片段来自于http://outofmemory.cn

标签:python,系统

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2014-07-03 21:54:51python获得磁盘剩余空间 statvfs by 风云轩
  2. 2014-07-04 20:43:50python windows平台锁定键盘 by 司马
  3. 2014-07-05 16:45:44Python 调用默认浏览器 by 司马
  4. 2014-10-22 16:18:49python, shell, golang获取本机IP地址 by 阮小七
  5. 2014-08-27 14:53:59获得本机硬件信息 by xwz
  6. 2014-09-15 12:22:25删除windows垃圾文件 by wubai
  7. 2013-06-04 13:43:27web.py中自定义jinja2模块 by 赵小全
  8. 2014-07-02 16:43:42py关闭显示器 by Solon.Ring
  9. 2014-07-03 18:50:14查看系统启动项 by 张宋付
  10. 2014-06-29 14:58:56自动更改网关 by 张宋付
  11. 2018-08-21 11:54:27java代码判断数字是否是2的n次方 by 甄码农

发表评论