Hi,

I would like to create a script which is able to check if it is being run in
an terminal service session.
It should only be allowed to run locally and not remotely.

Anyone any ideas?

Many thanks,
Jo

Re: Check if connected using Terminal Services by Torgeir

Torgeir
Mon Nov 29 12:07:56 CST 2004

Jo wrote:

> Hi,
>
> I would like to create a script which is able to check if it
> is being run in an terminal service session.
> It should only be allowed to run locally and not remotely.
Hi

Check the environment variable %SESSIONNAME%. If it is
non-existent or contains the value Console, you are not
running in a terminal service session.

This should work:

'--------------------8<----------------------
Set oShell = CreateObject("WScript.Shell")
Set oProcessEnv = oShell.Environment("PROCESS")
sSessionName = oProcessEnv("SESSIONNAME")

If sSessionName = "" Or LCase(sSessionName) = "console" Then
WScript.Echo "Running locally!"
End If
'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Check if connected using Terminal Services by Don

Don
Mon Nov 29 15:06:46 CST 2004

sTermServ = WshShell.ExpandEnvironmentStrings("%SESSIONNAME%")

'Test for Terminal Server connection, as it returns ie. RDP-Tcp#12 (Session
Number)
If Left(sTermServ,8) = "RDP-Tcp#" Then
'We are in a terminal Server Session
End If


"Jo" <Jo@discussions.microsoft.com> wrote in message
news:668FB67C-DD41-4A6C-94E7-36E90610F583@microsoft.com...
> Hi,
>
> I would like to create a script which is able to check if it is being run
> in
> an terminal service session.
> It should only be allowed to run locally and not remotely.
>
> Anyone any ideas?
>
> Many thanks,
> Jo