Why not use WMI? Because the execution is very slow, why not winreg? Because WinReg is inconvenient in terms of bulk acquisition and traversal of services, this method is used
This method is executed with WMIC under the command line
Get Service Information
# Coding=utf8 from Import = GetObject ("winmgmts:"= mywmi. InstancesOf ("win32_service" for in OBJS: Print
Get process Information
# Coding=utf8
from Import = GetObject ("winmgmts:"= mywmi. InstancesOf ("win32_process" for in OBJS: # Print
The code of execution is inspired by the following text:
VB use WMI to get the system current process details/list, VB use WMI to get the system current process information/list, VB use WMI to get the system process information/list, VB use WMI to get the current process information/list, VB use WMI to get process information/list, VB WMI Get current process information/list, VB WMI system process details/list, VB WMI process list, VB WMI process information, VB WMI process, VB Wmi,getobject ("winmgmts://./root/cimv2:win32_process"). Instances,winmgmts://./ROOT/CIMV2:WIN32_PROCESS,VB winmgmts://./root/cimv2,vb Win32_process,vb GetObject, Process Name: wmi.name, Process path: Wmi.executablepath, number of threads: wmi.threadcount,pid:wmi.processid, parent PID:Wmi.ParentProcessID, Priority: wmi.priority, command Line: Wmi.commandline, Memory consumption: wmi.workingsetsize/1024 & "K", User name: Wmi.execmethod_ ("GetOwner"). User, Startup time: Wmi.creationdate, another way to get the PID function: Wmi.handle. VB uses WMI to get the current process details of the system: Dim Wmi, Jic as Stringfor each Wmi in GetObject ("winmgmts://./root/cimv2:win32_process"). Instances_'Looping ProcessJic = Jic &" "& _"Process:"& Wmi.name &" "& _"Path:"& Wmi.executablepath &" "& _"Threads:"& Wmi.threadcount &" "& _"PID:"& Wmi.processid &" "& _"Parent PID:"& Wmi.parentprocessid &" "& _"Priority level:"& Wmi.priority &" "& _"command line:"& Wmi.commandline &" "& _"Memory:"& Wmi.workingsetsize/1024x768&"K"&" "& _"User:"& Wmi.execmethod_ ("GetOwner"). User &" "& _"Start time:"& Wmi.creationdate &" "&vbCrLf'"PID:" & Wmi.handle'another kind of acquiring PID function NextMsgBox JICVB"winmgmts://./root/cimv2"detailed usage of the object: • GetOwner () Gets the process user name. Usage: Objgetowner (variable name) Terminate () end process. Usage: obj. Terminate () Property: PID of the ProcessID process. Number of threads ThreadCount process ExecutablePath The full path of the process
Python calls Win32com.client's GetObject to find process information and service information