|
Answer» I know you can do it (if not very well) in batch using 'tasklist' and 'fc'. But is it possible to do with vbs?' This computer strComputer = "."
'Access WMI Object Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Get a collection of all running tasks Set ColRunningTasks = objWMIService.InstancesOf("Win32_Process")
'Iterate through them showing 2 of the named properties for each For Each Task In ColRunningTasks WScript.Echo Task.ProcessId & ":" & Task.NAME Next
These properties are available (that I know of, they are the column headers you see when you do WMIC Process List at the COMMAND line)
(Not all return values in the above script)
CommandLine CSName Description ExecutablePath ExecutionState Handle HandleCount InstallDate KernelModeTime MaximumWorkingSetSize MinimumWorkingSetSize Name OSName OtherOperationCount OtherTransferCount PageFaults PageFileUsage ParentProcessId PeakPageFileUsage PeakVirtualSize PeakWorkingSetSize Priority PrivatePageCount ProcessId QuotaNonPagedPoolUsage QuotaPagedPoolUsage QuotaPeakNonPagedPoolUsage QuotaPeakPagedPoolUsage ReadOperationCount ReadTransferCount SessionId Status TerminationDate ThreadCount UserModeTime VirtualSize WindowsVersion WorkingSetSize WriteOperationCount WriteTransferCount These come BACK blank on my system (Win 7 64, SP1)
ExecutionState InstallDate Status TerminationDate
If you wanted to know if a particular task was running you could do something like this
' This computer strComputer = "."
'Access WMI Object Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Get a collection of all running tasks Set ColRunningTasks = objWMIService.InstancesOf("Win32_Process")
TestTaskName="notepad.exe" Running = False
'Iterate through them comparing name property with wanted task name For Each Task In ColRunningTasks 'make both strings LOWER case to force case INSENSITIVE compare If lcase(Task.Name) = lcase(TestTaskName) then Running = True End If Next
If Running = True then Result = " is running" Else Result = " is not running" End If
Wscript.echo TestTaskName & Result
|