Terminal services – Understanding it better

sherpajj
sherpajj used Ask the Experts™
on


When I loginto my Terminal services acct, and get disconnected, and log back in again…
it opens a new session.      

I want to get back to my old session with all the windows I had oped.  I don’t want a new session.


When this second session gets disconnected, and I go to log back in, it asks me which of the 2 previous sessions I want to join and makes me pick one.  there is no starting a 3rd session.

I am running win 2003 server.

I know there is a setting limiting each user to 1 login, but I wonder how to specifiy an old session when reconnecting, how to stop it from always starting a new session


thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Not sure if this will work on 2003 but may be worth a try...



This is an example of how to use the tscon command to connect to another session on the current Terminal Services server:
In a Terminal Services session, click Start, and then click Run.
Type cmd, and then click OK.
Determine the name or ID of the session to which you want to connect. To do so, type 'query session' (without quotes), and then press ENTER. You see a list of information about the sessions on the current Terminal Services server. The list may be similar to this:

SESSIONNAME   USERNAME        ID      STATE    TYPE    DEVICE
 console      administrator       0   active   wdcon  
 rdp-tcp                      65536    listen    rdpwd
rdp-tcp#1    user1               1   active   rdpwd
rdp-tcp#2    user1               2   active   rdpwd
rdp-tcp#3    user2               3   active   rdpwd
rdp-tcp#4    user3               4   disc      rdpwd  
rdp-tcp#5    user1               5   disc      rdpwd
                                            6   idle
                                            7   idle
                                    
Note that in this example, the name of the current session is rdp-tcp#1, the session ID is 1, and the session is owned by user1.


To connect to session 2, type the following line at the command prompt, and then press ENTER:
tscon 2 /v

You see the following line:
Connecting sessionID2 to sessionname rdp-tcp#1

The current session (session 1) is disconnected, and you are connected to Session 2.


To connect to session 1 (from session 2), type the following line at the command prompt, and then press ENTER:
tscon 1

The current session (session 2) is disconnected, and you are connected to session 1.


To connect session 5 to session 2 from another session, type the following line at the command prompt, and then press ENTER:
tscon 2 /v /dest:rdp-tcp#5

You see the following line:
Connecting sessionID2 to sessionname rdp-tcp#5

Session 2 is connected to session 5, and session 5 is disconnected.


To connect to session 4 (which is owned by User3), type the following line at the command prompt, where User3Pass is the password for User3, and then press ENTER:
tscon 4 /password:User3pass

The current session disconnects, and you are connected to session 4.
I am having the same problem...when a user gets diconnected and logs back in, it logs them into a new session instead of their disconnected session.  The only way I can get them back to their original disconnected session is by disconnecting the second session and logging in again.  After the second disconnect and third login, it will ask you which session you want to enter.  They can use this to get back to their original session.  

I am not sure if this question was really answered:  How do you prevent it from logging into a new session after you have been disconnected.  It should go back into the disconnected session no matter what unless their are no sessions at all in which case it would create a new one.  I am looking at fixing this for computer illiterate user, so the comman prompt steps above are out of the question.  Does anyone else know how I may fix this?

Commented:
I too am having the same problem. The TSCON commands are helpful, but is there a way to RESET the session instead of just disconnecting? Why is it opening a new session instead of reconnecting them?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

TERMINAL SERVICES ON WINDOWS 2000 SERVER OPENS NEW SESSION INSTEAD OF RECONNECTING TO EXISTING DISCONNECTED SESSION

I have the same problem, normally when reconnecting to the Terminal Server from which you may have been disconnected due to power supply etc., you should be reconnected to your previous disconnected session and make it active again.

What happens now is that you have 2 sessions, 1 Active and 1 Disconnected.

The TS should only create a new session if you you have another ACTIVE session.

This is very troblesome for us as we have our users connect to the terminal server with no access to the desktops, and launch their sessions starting up our ERP solution. When they are disconnected and reconnect to a new session, the ERP solution obviously asks them to login again, but then receive an error that they are already logged into the database, as their DISCONNECTED session still has an active ERP session going for them.

The only solution I have is to assist the user to connect the users manually to TS desktop and reconnect them to their DISCONNECTED session, this is obviously less than ideal.

ANY IDEAS ??
I see that Windows 2003 Enterprise Edition has a Session Directory is nothing more than a database that keeps track of which users are running which sessions on which servers. This information is used when a user wants to disconnect from a session and then reconnect back to it in multi-server environments. Without the Session Directory, the system would not know that the user had a disconnected session on a server and might route her to a different server where she would start a new session. In addition to being annoying for the user, this is a waste of resources. A single user could leave many orphan sessions throughout the environment.

See http://www.brianmadden.com/content/content.asp?id=279

Anu Ideas on how TS2000 sessions can forced to reconnect to disconnected sessions ?

Commented:
I just installed Windows 2003 and Terminal now has an option you can setup that prevents multiple logins. This upgrade has solved all the problems. However, before I upgraded I built a batch file that did the same thing. I put the batch file into the startup. I will post the batch file. This file checks if a previous session is disconnected and closes the current session then puts the user back into the old session. It works like a charm. Let me know if you need any help editting the batch file to suit your needs. BTW, replace "kenga02" with the computer name of your terminal server.

single_logon_and_reconnect.bat
---------------------------------------------------------------------------------------------------------------------------------------

@echo off

SetLocal
Set LoginNum=0
Set LoginCount=0
Set SessNum=-1
rem For /f "skip=2 delims=* " %%i in ('qappsrv') do call :Next %%i

call :Next kenga02 %1

Rem LoginNum will be less than or equal to 1 if the user is only logged in once.
Rem This is good, and the script will then terminate
If %LoginNum% LEQ 1 (EndLocal) && (Goto EoF)

Rem LoginNum will be equal or greater than 2 if the user is logged in already

Rem The user is logged in more than once...so find the session number of the other session
For /f "skip=1 tokens=3" %%i in ('qwinsta %UserName% ^| find /v ">"') Do set SessNum=%%i

Rem This should never happen, unless the person is on a different server...
If %SessNum% EQU -1 (Call :Error 1) && (Goto EoF)

Rem Check what OS we are running:
Rem Windows 2000/2003 or NT?
If Exist %SystemRoot%\System32\TSCon.exe (TSCon.exe %SessNum%) Else (Connect.exe %SessNum%)
If %ERRORLEVEL% NEQ 0 (Call :Error 2) && (Goto EoF)
EndLocal
Logoff.exe
Goto EoF

:Error
Rem This is bad, so warn the user, then log them off
Msg %WinStationName% /W You are logged on at another server.  You need to log out of there before you can log in again.  (Error Code: %1)
Logoff.exe
EndLocal
Goto EoF

:Next
Rem Checking the servers to see where the user is and update the count...
For /f %%j in ('qwinsta /server:%1 ^| find /c /i " %2 "') do Set /A LoginNum=%LoginNum%+%%j
Goto EoF

:EoF


---------------------------------------------------------------------------------------------------------------------------------------


Cheers!! Let me know if you need help with the batch file.
Thank you very much for the excellent advice. As I am running my ERP solution on 2 terminal servers  hosting the application linked to a SQL box.

I found a simialr resource on http://terminal.servebeer.com/php/check_logon_and_connect.php but it does not address the issue if the user is already logged into another server, which yours does.

I will give this a twirl, please confirm what your meanby 'I put the batch file into the startup' as I already have my users terminal server sessions starting with the ERP solution. Where excatly do you suggest the script must be launched from. In the Terminal Services Configuration ?

Regards

Pieter

Commented:
What I have done is added a shortcut to the batch file in the Programs Startup folder for each user, so it'll execute whenever someone logs in. (i.e. C:\Documents and Settings\Username\Start Menu\Start Up\)

I'm not sure how you are setup on your Terminal Server, but this would be the default setup. This is pretty much the quickest and easiest way. It gets more complicated if you try to put this batch file into your domain policy settings.

The batch file worked like a charm for my setup as long as you make sure the batch file starts up whenever someone attempts to login. The Start Up folder is the easiest way that I know of.

I hope this helps, please let me know if you need more info to get this setup. I understand how frustrating it is to have users open multiple sessions and then spending your day killing those sessions.

Again, Windows Server 2003 solves this problem by allowing you to specify if you allow multiple logins or not from a single user.
Placing the scripts in the C:\Documents and Settings\Username\Start Menu\Start Up\ does not work if the users do not have access to the desktop.

We use the TS servers only for deploying the ERP solution, and they are therefore limited to this only, their RDP shortcuts have the option ticked 'Start the following program on connection' - c:\eentrprs\enmaster\dynamics.exe c:\eentrprs\enmaster\dynamics.set

This launches Great Plains auotmatically, so that when they enter their windows login, they are immediately prompted for their Great Plains login.

Any idea how I can  ensure they reconnect using your script in another location ?

Commented:
I am not familiar with ERP or Great Plains, but you might want to try the following:

- Go in and Edit your Group Policy
- Go into User Configuration
- Windows Settings
- Scripts (Logon/Logoff)
- Right click Logon and go into Properties
- Click the Add button

From there you should be able to add any script you want. I have a script in there that Maps some drives and adds some printers. Try putting the script in there and let me know how it goes.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial