Solved

code to detect if an application is running under terminal server

Posted on 2006-11-17
3
666 Views
Last Modified: 2008-01-09
I have vb application I want to check if it is running on windows terminal services or local LAN so that I can decide certain things

I have tried this

Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
....

if LoadLibrary("wtsapi32.dll") <> 0 then
  ' in Terminal server
else
  ' not in terminal server
end if


But its giving me wrong result :(
0
Comment
Question by:RETAILREALM
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 17969765
Try

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

Public Function IsRemoteSession() As Boolean
   IsRemoteSession = GetSystemMetrics(SM_REMOTESESSION)
End Function
0
 
LVL 27

Expert Comment

by:Ark
ID: 17969884
PS ubove code is for w2K and up, not sure about NT4

You can also try to use Environ("SESSIONNAME") variable:

Public Function IsRemoteSession() As Boolean
   dim s as string
   s=Environ("SESSIONNAME") 'Check for Terminal service enabled and running
   if s="" then exit function   'disabled
   if s="console" then exit function 'not running
   s=Environ("CLIENTNAME") 'check for XP remote desktop (not real TS)
   if s="" then exit function
   IsRemoteSession = True
End Function
0
 

Author Comment

by:RETAILREALM
ID: 17977459
Hi  Ark


It’s working perfectly

Thank you very much
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now