Task Manager in Excel – How to use Excel to Monitor Servers or PC?
There are in built application in Windows to view what applications are currently running in your machine, like Task Manager (taskmgr.exe), Performance Monitor (perfmon.exe), Task List (Tasklist.exe).
Anyone can use these applications to monitor tasks/processes/applications/services currently executing in a Windows Machine.
If we suspect any performance or security issue then we usually use these Application Monitoring softwares to check whether any Task is using more memory or CPU.
In case of a PC on can use this manual process. But in case of business critical applications running in a Server system, there is need for an automated process that can monitor the application and system performance.
From this article, we can learn some basics about how to build simple Application Monitoring automation software.
Read Task Manager Applications to Excel
As we know that the Task Manager has the list of softwares currently executed by CPU.
To monitor those processes, we first need to read that list with Excel macro and write it into any worksheet.
First we will be creating an object for Windows Management class and then execute a SQL type of query to pull list of running processes.
There are other different type of queries that can be executed against ‘winmgmts’ to fetch system properties like Motherboard serial number, Manufacturer, model, MAC address, Hard Disk serial numbers etc.,
Option Explicit 'This code is downloaded from Officetricks.com 'Visit our site for more Free Excel Code Sub Task_List_In_Excel() Dim oMgmt As Object, oProc As Object, oList As Object Set oMgmt = GetObject("winmgmts:") Set oProc = oMgmt.ExecQuery("Select * from Win32_Process") i = 1 'Loop thru each process and application name For Each oList In oProc ThisWorkbook.Sheets(1).Cells(i, 1) = oList.Name i = i + 1 Next End Sub
There are different methods to do this. One method is to use the Windows Management Object and query it for running processes. Other possible method uses Windows API functions. Click this lick to learn about the alternate process.
Also Read: Adding A ToolTip To Any Cell In Excel
Terminate Process or Kill Application in Task Manager
The FOR loop in the above, reads each task name and writes it into Excel worksheet. Now, while reading it, we can make the code to check for any application name and terminate it as in below code.
For Each oList In oProc 'Check for Application Name. Kill Process if there is a Match If vba.Ucase(oList.Name) = vba.Ucase("notepad.exe") Then oList.Terminate End If Next
Similar to the above code, any unwanted application can be terminated.
To Build Actual Application Monitor
All we have presented above is just few code snippets to show how to fetch and terminate processes. But this does not make a complete Automated Task Monitor.
To build it, we also need to get code from the below pages and integrate them.
- Continuously Monitor the tasks on certain time interval. To do this, we need to have a Timer functionality in Excel.
- Schedule and Execute tasks. Refer this page.
By integrating all these code, we can Schedule, Manage, Initiate and Terminate Tasks right from Excel.