主机性能监控之wmi 获取进程信息
标 题: 主机性能监控之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 获取进程信息的更多相关文章
- 主机性能监控之wmi 获取磁盘信息
标 题: 主机性能监控之wmi 获取磁盘信息作 者: itdef链 接: http://www.cnblogs.com/itdef/p/3990541.html 欢迎转帖 请保持文本完整并注明出处 仅 ...
- 主机性能监控之wmi 获取系统信息及内存性能信息
标 题: 主机性能监控之wmi 获取系统信息及内存性能信息作 者: itdef链 接: http://www.cnblogs.com/itdef/p/3990240.html 欢迎转帖 请保持文本完整 ...
- WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法
原文:WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法 今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都是可以提取出来的,就自己把那些公共部分提出出来,以后如果要获取 某部分的 ...
- Qt 扫描进程列表以及获取进程信息
使用方法: QMap<QString,qint64> app_pid; getAllAppPidList( app_pid ); #include <tlhelp32.h>// ...
- VC中遍历进程并获取进程信息
代码如下: /***************************************************/ /* 函数: 遍历进程信息 /* 参数:进程名称 例如: aaa.exe /* ...
- 通过WMI获取机器信息
PerformanceCounter的介绍就不多说了,MSDN上介绍的很详细: https://msdn.microsoft.com/zh-cn/library/system.diagnostics. ...
- C#通过WMI获取硬件信息
有时候需要得到硬件信息绑定用户登录 代码如下: private string GetProcessSerialNumber() { try { ManagementObjectCollection P ...
- 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 ...
- WMI获取进程CPU占用率
Monitor % Process CPU Usage (specific process) http://www.tek-tips.com/viewthread.cfm?qid=395765 for ...
随机推荐
- 轻量应用服务器 访问jsp页面就直接下载的问题
本地localhost 运行可以 用自己的ip不行.出现这个问题实质原因就是Tomcat服务器就没有起到作用,运行不了jsp文件.这个是核心.去排查错误!网上查了好几天了根本没有解决我的我的问题. 1 ...
- 前端-JavaScript1-3——JavaScript之字面量
字面量?????? 字面量:英语叫做literals,有些书上叫做直接量.看见什么,它就是什么. 我们先来学习数字的字面量,和字符串的字面量.剩余的字面量类型,我们日后遇见再介绍. 3.1 数字的字面 ...
- Pod配置PersistentVolumeClaim详解
1,创建PersistentVolume kind: PersistentVolume apiVersion: v1 metadata: name: task-pv-volume labels: ty ...
- keil5 MDK 链接报错 Error: L6410W 解决
keil5 MDK 报错 Build target 'Project' linking... .\Output\Project.axf: Warning: L6310W: Unable to find ...
- ef中文文档
https://entityframework.net/zh-CN/home 在使用ef进行对数据库操作时 数据库迁移 https://www.dotnettricks.com/learn/entit ...
- 删除文件夹下各级子目录中的.svn文件
建立一个文本文件,取名为removeSvn.reg(扩展名由txt改为reg),内容如下 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHIN ...
- 完整安装always on 集群
1. 四台已安装windows server 2008 r2 系统的虚拟机,配置如下: CPU : 1核 MEMORY : 2GB DISK : 40GB(未分区) NetAdapter : 2块 ...
- Requests对HTTPS请求验证SSL证书
SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secure socket layer(SSL)安全协议是由Netscape Communication公司设计开发.该安全协议主 ...
- 基于Dubbo框架构建分布式服务(集群容错&负载均衡)
Dubbo是Alibaba开源的分布式服务框架,我们可以非常容易地通过Dubbo来构建分布式服务,并根据自己实际业务应用场景来选择合适的集群容错模式,这个对于很多应用都是迫切希望的,只需要通过简单的配 ...
- centos7 卸载 jdk
################ jdk 的安装 ###########################参考:https://www.cnblogs.com/Dylansuns/p/6974272.h ...