标 题: 主机性能监控之wmi 获取进程信息
作 者: itdef
链 接: http://www.cnblogs.com/itdef/p/3990499.html

欢迎转帖 请保持文本完整并注明出处

仅在《主机性能监控之wmi 获取系统信息及内存性能信息》 代码中添加一个函数

使用的结构体位为Win32_Process

class Win32_Process : CIM_Process
{
string Caption;
string CommandLine;
string CreationClassName;
datetime CreationDate;
string CSCreationClassName;
string CSName;
string Description;
string ExecutablePath;
uint16 ExecutionState;
string Handle;
uint32 HandleCount;
datetime InstallDate;
uint64 KernelModeTime;
uint32 MaximumWorkingSetSize;
uint32 MinimumWorkingSetSize;
string Name;
string OSCreationClassName;
string OSName;
uint64 OtherOperationCount;
uint64 OtherTransferCount;
uint32 PageFaults;
uint32 PageFileUsage;
uint32 ParentProcessId;
uint32 PeakPageFileUsage;
uint64 PeakVirtualSize;
uint32 PeakWorkingSetSize;
uint32 Priority;
uint64 PrivatePageCount;
uint32 ProcessId;
uint32 QuotaNonPagedPoolUsage;
uint32 QuotaPagedPoolUsage;
uint32 QuotaPeakNonPagedPoolUsage;
uint32 QuotaPeakPagedPoolUsage;
uint64 ReadOperationCount;
uint64 ReadTransferCount;
uint32 SessionId;
string Status;
datetime TerminationDate;
uint32 ThreadCount;
uint64 UserModeTime;
uint64 VirtualSize;
string WindowsVersion;
uint64 WorkingSetSize;
uint64 WriteOperationCount;
uint64 WriteTransferCount;
};

添加函数为

 bool CMyWMI::QueryProcessInfo()
{
HRESULT hres; //定义COM调用的返回
IEnumWbemClassObject* pEnumerator = NULL;
bool bRet = false; try{
hres = pSvc_->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Process"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator); if (FAILED(hres))
{
throw exception("ExecQuery() error.");
} while (pEnumerator)
{
IWbemClassObject *pclsObj;
ULONG uReturn = ; HRESULT hr = pEnumerator->Next(WBEM_INFINITE, ,
&pclsObj, &uReturn);
if( == uReturn)
{
break;
} GetInfo(L"Caption",pclsObj);
GetInfo(L"Handle",pclsObj);
GetInfo(L"ExecutablePath",pclsObj);
cout << endl; pclsObj->Release();
} }catch(exception& e)
{
cout << e.what() << endl;
if(pEnumerator != NULL)
{
pEnumerator->Release();
pEnumerator = NULL;
}
return bRet;
} if(pEnumerator != NULL)
{
pEnumerator->Release();
pEnumerator = NULL;
} bRet = true;
return bRet;
}

python代码

#!/usr/bin/env python
# -*- coding: cp936 -*- import wmi
import os
import sys
import platform
import time def process_info():
c = wmi.WMI()
for p in c.Win32_Process():
print p.ProcessId, p.Name , p.ExecutablePath def main():
process_info(); if __name__ == '__main__':
main()

效果:

Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
0 System Idle Process None
4 System None
316 smss.exe None
448 csrss.exe None
520 wininit.exe None
548 csrss.exe None
596 services.exe None
604 lsass.exe None
612 lsm.exe None
640 winlogon.exe None
760 svchost.exe None
820 BaiduHips.exe None
852 BaiduSdSvc.exe None
932 BaiduAnSvc.exe None
1004 svchost.exe None
352 atiesrxx.exe None
1068 svchost.exe None
1232 svchost.exe None
1260 svchost.exe None

												

主机性能监控之wmi 获取进程信息的更多相关文章

  1. 主机性能监控之wmi 获取磁盘信息

    标 题: 主机性能监控之wmi 获取磁盘信息作 者: itdef链 接: http://www.cnblogs.com/itdef/p/3990541.html 欢迎转帖 请保持文本完整并注明出处 仅 ...

  2. 主机性能监控之wmi 获取系统信息及内存性能信息

    标 题: 主机性能监控之wmi 获取系统信息及内存性能信息作 者: itdef链 接: http://www.cnblogs.com/itdef/p/3990240.html 欢迎转帖 请保持文本完整 ...

  3. WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法

    原文:WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法 今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都是可以提取出来的,就自己把那些公共部分提出出来,以后如果要获取 某部分的 ...

  4. Qt 扫描进程列表以及获取进程信息

    使用方法: QMap<QString,qint64> app_pid; getAllAppPidList( app_pid ); #include <tlhelp32.h>// ...

  5. VC中遍历进程并获取进程信息

    代码如下: /***************************************************/ /* 函数: 遍历进程信息 /* 参数:进程名称 例如: aaa.exe /* ...

  6. 通过WMI获取机器信息

    PerformanceCounter的介绍就不多说了,MSDN上介绍的很详细: https://msdn.microsoft.com/zh-cn/library/system.diagnostics. ...

  7. C#通过WMI获取硬件信息

    有时候需要得到硬件信息绑定用户登录 代码如下: private string GetProcessSerialNumber() { try { ManagementObjectCollection P ...

  8. python——psutil的使用(获取进程信息)

    import psutil psutil.pids() [1, 2, 3, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 26, 27, 28, 2 ...

  9. WMI获取进程CPU占用率

    Monitor % Process CPU Usage (specific process) http://www.tek-tips.com/viewthread.cfm?qid=395765 for ...

随机推荐

  1. DataTable.Select 处理关联表数据

    DataSet.Clone  会拷贝表结构,关联关系也会拷贝, 用Select 筛选后ImportRow 导入新的DataTable,然后处理关联DataTable DataSet ds2 = dsS ...

  2. python修改字典的值(update map value)

    mydict.update({'newkey':'newvalue'})

  3. 涂抹mysql笔记-搭建mysql高可用体系

    mysql的高可用体系<>追求更高稳定性的服务体系 可扩展性:横向扩展(增加节点).纵向扩展(增加节点的硬件配置) 高可用性<>Slave+LVS+Keepalived实现高可 ...

  4. 爬虫基础线程进程学习-Scrapy

    性能相关 学习参考:http://www.cnblogs.com/wupeiqi/articles/6229292.html 在编写爬虫时,性能的消耗主要在IO请求中,当单进程单线程模式下请求URL时 ...

  5. day39数据库之基本数据类型

    数据库之数据类型1.数据存储引擎 一个功能的核心部分,回到mysql        核心功能是存储数据  涉及到存储数据的代码 就称之为存储引擎        根据不同的需求 也有着不同的引擎分类 不 ...

  6. Python全栈开发记录_第一篇(循环练习及杂碎的知识点)

    Python全栈开发记录只为记录全栈开发学习过程中一些难和重要的知识点,还有问题及课后题目,以供自己和他人共同查看.(该篇代码行数大约:300行) 知识点1:优先级:not>and 短路原则:a ...

  7. C# 设置Excel数字格式

    数字格式使指能够控制Excel单元格中数字如何显示的格式字符串.例如,我们可以对数字12345应用数字格式“0.00”,使之显示为“12345.00”.在例如对数字12345应用“¥0.00”格式,使 ...

  8. java后台解析前端传来的json

    @RequestMapping(value = {"save"}) @ResponseBody public Result save(TBaseInterventionPlan m ...

  9. 【原】The Linux Command Line - Redirection

    ● cat - Concatenate files● sort - Sort lines of text● uniq - Report or omit repeated lines● grep - P ...

  10. hdu5698瞬间移动-(杨辉三角+组合数+乘法逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...