3

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.

1

1 Answer 1

14

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
1
  • Just what I needed. Thanks.
    – ib11
    Sep 10, 2016 at 0:16

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.