Development‎ > ‎VBScript‎ > ‎

Count processes

Code:
'*********************************************************************************
'* Function signature:
'* Description:
'*              
'*
'* Parameters
'*
'*
'*
'* Return Value
'*
'*********************************************************************************
Function gen_CountRunningProcesses(sProcessName)
      Dim iCount : iCount = 0
     
      Dim strComputer, objWMIService, colProcessList, objProcess
      strComputer = "."
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
      'get the process based upon the Parameter
      Set colProcessList = objWMIService.ExecQuery _
            ("SELECT * FROM Win32_Process WHERE Name = '" & sProcessName &"'")
     
      For Each objProcess in colProcessList
            iCount = iCount + 1
      Next
     
      Set colProcessList = Nothing
      Set objWMIService = Nothing
 
      gen_CountRunningProcesses = iCount
End Function

Comments