主机性能监控之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 ...
随机推荐
- 解压zipfile & tarfile
def __un_zip(self, file_path): """解压.zip格式文件到同名目录下,若解压之前就存在该目录说明已解压,跳过解压过程,返回该目录" ...
- 前端-JavaScript1-4——JavaScript之变量
变量(Variables),和高中代数学习的x.y.z很像,它们不是字母,而是蕴含值的符号. 它和直接量不同,直接量5,就是数字5:直接量”你好”就是字符串“你好”.现在这个变量不一样了,你看见一个a ...
- 刘志梅 201771010115 《面向对象程序设计(java)》 第七周学习总结
实验七 继承附加实验 实验时间 2018-10-11 1.实验目的与要求 (1)进一步理解4个成员访问权限修饰符的用途: 即将类中的域标记为private,而方法标记为public.任何声明为priv ...
- Chrome默认搜索引擎被窜改
折腾了几个安全软件之后,Chrome浏览器默认搜索引擎被窜改,且无法删除,提示“管理员安装”,另外在插件栏出现了一个unTabs的东西,也无法删除,“受政策保护之类的”.搜索后找到一篇文章“Unabl ...
- node.js打印function
var Person = function(name) { this.name = name; this.gender = ['man', 'woman']; } console.log(Person ...
- 红黑树Python实现
# coding=utf-8 # 红黑树Python实现 # 颜色常量 RED = 0 BLACK = 1 def left_rotate(tree, node): if not node.right ...
- thinkphp5 与 endroid 二维码生成
windows compser安装endroid/qrcode,自己安装好composer工具; 1. 项目目录 文件 composer.json require 里添加 "endroid/ ...
- Python中xlrd和xlwt模块使用方法
本文主要介绍可操作excel文件的xlrd.xlwt模块.其中xlrd模块实现对excel文件内容读取,xlwt模块实现对excel文件的写入. 安装xlrd和xlwt模块 xlrd和xlwt模块不是 ...
- matlab-可视化图像阈值选择GUI工具
话不多说,先看图,这是导入一张图后运行的效果. 在此函数中,左图是灰度图加上colorBar后的彩色效果图,右图是二值化后的图,下面是可调节阈值的灰度直方图. 左上角的按钮是回归初始状态,右上角的按钮 ...
- leetcode771
int numJewelsInStones(string J, string S) { set<char> st; ; for (auto c : J) { st.insert(c); } ...