首先編寫進程監視器
首先介紹一下pywin32
Python extensions for Microsoft Windows Provides access to much of the Win32 API , the ability to create and use COM objects, and the Pythonwin environment.
再介紹一下wmi,wmi主要用于
Windows驅動程序模型的一組擴展,它提供操作系統接口,檢測組件可通過該接口提供信息和通知。
?
使用一個.csv文件,用于存儲進程信息
然后初始化進程監視器,再創建進程。
將進程信息寫入.csv文件中
import os
import wmi
def log_message(message):
f=open("message.csv","ab")
f.write("%s\r\n"%message)
f.close()
log_message("Time,User,Executable,CommandLine,PID,Parent PID,Privileges")
c=wmi.WMI()
process_monitor=c.Win32_Process.watch_for("creation")
while True:
try:
new_process=process_monitor()
proc_owner=new_process.GetOwner()
proc_owner="%s\\%s"%(proc_owner[0],proc_owner[2])
create_data=new_process.CreationDate
executable=new_process.ExecutablePath
cmdline = new_process.CommandLine
pid = new_process.ProcessId
parent_pid = new_process.ParentProcessId
privileges = "N/A"
process_log_message="%s,%s,%s,%s,%s,%s,%s\r\n"%(create_data,proc_owner,executable,cmdline,pid,parent_pid,privileges)
print process_log_message
log_message(process_log_message)
except:
pass
這里進程的加載速度有點慢,可以考慮開啟多線程,不過這里應該是指令密集型的程序,開啟多線程加的速度應該不會很快
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

