VB Script: How to tell if a program is already running?

16,729

I'm currently using this function.

Just call it like this IsProcessRunning "compname","mstsc.exe"

Function IsProcessRunning( strComputer, strProcess )
    Dim Process, strObject
    IsProcessRunning = False
    strObject   = "winmgmts://" & strComputer
    For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
    If UCase( Process.name ) = UCase( strProcess ) Then
        IsProcessRunning = True
        Exit Function
    End If
    Next
End Function
Share:
16,729
Pratt Hinds
Author by

Pratt Hinds

Updated on June 05, 2022

Comments

  • Pratt Hinds
    Pratt Hinds almost 2 years

    I am writing a script to open an RDP session, but I want to check to see if an RDP session is already running. My initial thought is to check for MSTSC.EXE running in memory. Any idea how to do this?

    Open to alternative solutions for the problem as well. Trying to prevent a client from logging into an RDS server twice. Multiple logins are allowed because the same user may log in from different clients.