Solved

code to detect if an application is running under terminal server

Posted on 2006-11-17
3
694 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
Run code from text file in vb 1 84
Copy a row 12 69
Child Form in front 4 56
add criteria to query in VB, Access 2003 2 29
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 …
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…
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…

685 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