preload

DotNetFactory interface functions – SysProcessExists

Posted by Albert Gareev on Jan 04, 2011 | Categories: DotNetClassesSource code

Check If a Process Exists in Memory

Parent page: Service Functions – DotNetFactory (QTP, VBScript)

Description

Create an instance of Process object through DotNetFactory – search for local processes by name – return result as boolean.

Note. Name is case-insensitive but no wildcards supported.

Implementation

Public Function SysProcessExists(ByVal sName)
 Dim objSDP
 Dim objSDPArr
 Dim boolRC
 
 Set objSDP = DotNetFactory.CreateInstance("System.Diagnostics.Process", "System")
 Set objSDPArr = objSDP.GetProcessesByName(sName)

 boolRC = CInt(objSDPArr.length) > 0

 Set objSDP = Nothing
 Set objSDPArr = Nothing

 SysProcessExists = boolRC

End Function

Examples

Dim boolRCboolRC = SysProcessExists("winword")
if boolRC Then
  MsgBox("WinWord is running")
End If

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.