Search code examples
vb6remote-desktopterminal-services

How to detect whether in Terminal Services session in VB6?


How can you detect whether the current session is a Terminal Services (Remote Desktop) session in a VB6 app?


Solution

  • Calling the GetSystemMetrics function with the SM_REMOTESESSION flag will tell you whether the app is running inside a Terminal Services session.

    To call that from VB 6, you need to declare it in a module like so:

    Const SM_REMOTESESSION As Long = &H1000
    Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    

    If you are running inside of a Terminal Services environment, the return value will be non-zero.

    ...But you should really just fix your centering code, rather than trying to work around it with different behavior depending on whether you're running inside a Terminal Services session. That's just going to make more work for you and introduce more bugs. Unfortunately, I can't tell you what's wrong with the centering code you're using without seeing it.