Solved

code to detect if an application is running under terminal server

Posted on 2006-11-17
3
670 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now