Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

code to detect if an application is running under terminal server

Posted on 2006-11-17
3
Medium Priority
?
716 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
[X]
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
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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