Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if app is on terminal server 1

Status
Not open for further replies.

ThatRickGuy

Programmer
Oct 12, 2001
3,841
US
Just wondering if anyone has run into this before. I'm looking to impliment a version of Chrissie's code for auto updating an app, but terminal server is a bit of a pain, you can't x-copy over files on terminal server. (You can how ever uninstall/reinstall even if users are in the app!) Anyways, I need to find out if the app is running on terminal server so that I can prevent the auto-update code from running. Things I've tried:

Environment.OSVersion: returns "Microsoft NT 5.0.2195.0" I can not be sure that the machine is Terminal Server, or just a Win 2k client.

GetVersionEx API call GetVersionEx is pretty old, and while it can identify Windows NT Terminal Server, it can not identify Windows 2k Terminal Server.

Things yet to try: Looking in running services? Not sure where to start on that one.

Any ideas, thoughts, comments?

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Code:
 if messagebox.show("Are you using Terminal services???","Question??") = dialogresult.yes then
   'we have a TS
 else
   'we have No TS
 end if

[ROFL]

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Punk :p

Actually, I cheesed out. I went to ask the networkers if they knew of any way to uniquely identify a terminal server. After watching the net cheif check a few things (getting Windows_NT for all of them) he said, "Ya know, we should add an environment variable so we can tell that in our logon scripts"

made my life a hell of a lot simpler!

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick, this works under Citrix:

Code:
Dim Sh, Clientname, Computername
Set Sh = WScript.CreateObject("WScript.Shell")
Clientname =  UCase(Sh.ExpandEnvironmentStrings("%Clientname%"))
Computername =  UCase(Sh.ExpandEnvironmentStrings("%Computername%"))

If (Clientname <> "%CLIENTNAME%") And (Clientname <> Computername) Then
	IsTSSession = True
Else
	IsTSSession = False
End If

If IsTSSession Then
	WScript.Echo "This is a Terminal Services session"
Else
	WScript.Echo "This is NOT a Terminal Services session"
End If

I found it through Google. I've just been back into Google to try to find the author to credit him/her, but I can't seem to ask the correct question to call it up.

Another solution (Delphi based) that I've not tested but it looks good:


...check if we are running in a terminal client session?
Author: P. Below
0 Comments to this tip [Write new comment]
[ Print tip ]

Tip Rating (8):



Code:
function IsRemoteSession: Boolean;
const
  sm_RemoteSession = $1000; { from WinUser.h }
begin
  Result := GetSystemMetrics(sm_RemoteSession) <> 0;
end;


Hope this helps.
 
Never mind, I'm dumb. A little late binding and it's fine.

Code:
  Private Sub TryThisToo()
    Dim Sh, Clientname, Computername
    Dim IsTSSession As Boolean
    Sh = CreateObject("WScript.Shell")
    Clientname = UCase(Sh.ExpandEnvironmentStrings("%Clientname%"))
    Computername = UCase(Sh.ExpandEnvironmentStrings("%Computername%"))

    If (Clientname <> "%CLIENTNAME%") And (Clientname <> Computername) Then
      IsTSSession = True
    Else
      IsTSSession = False
    End If

    If IsTSSession Then
      MessageBox.Show("This is a Terminal Services session")
    Else
      MessageBox.Show("This is NOT a Terminal Services session")
    End If
  End Sub

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Even a bit more cleaned up:
Code:
  Private Function IsTSSession() As Boolean
    Dim Clientname As String
    Dim Computername As String
    Dim bRetVal As Boolean = False
    Clientname = Environment.ExpandEnvironmentVariables("%ClientName%")
    Computername = Environment.ExpandEnvironmentVariables("%ComputerName%")

    If (Clientname <> "%CLIENTNAME%") And (Clientname <> Computername) Then IsTSSession = True

    Return bRetVal
  End Function

No more WScript :)

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Maybe I should have finished testing this prior to having posted it... geah, you'll also want to check the Clientname.toupper against "%CLIENTNAME%". So last time, the full code should look like:

Code:
  Private Function IsTSSession() As Boolean
    Dim Clientname As String
    Dim Computername As String
    Dim bRetVal As Boolean = False
    Clientname = Environment.ExpandEnvironmentVariables("%ClientName%")
    Computername = Environment.ExpandEnvironmentVariables("%ComputerName%")

    If (Clientname.ToUpper <> "%CLIENTNAME%") And (Clientname <> Computername) Then bRetVal = True

    Return bRetVal
  End Function

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top