Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

code to detect if an application is running under terminal server

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

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 28

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

792 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