How can I restore a remote desktop session to the local console?
Solution 1
- Create a desktop shortcut by right clicking on the desktop and selecting new, then select shortcut.
-
In the text field enter:
%windir%\System32\tscon.exe 0 /dest:console
(See below) - Right click the newly created shortcut, click properties.
- Click the shortcut tab, and click the Advanced button.
- Check the "Run as administrator" box and click OK.
If this doesn't work, try changing the number zero (tscon.exe 0 /dest...
) in step 2 to the number one, and if it doesn't work, keep incrementing it until your remote desktop is released.
Alternately, open up a shell with start menu, run, cmd
. Type qwinsta
Enter, and look for the ID of the session that is in the active state (it will have a >
character at the start of its session name). That's the number you need to use in step 2.
When you want to restore the console desktop, just double click on the shortcut and allow the administrator access.
Solution 2
Here's a version which avoids the dependency on GNU tools. It uses findstr, which is shipped with Windows.
for /f %%i in ('qwinsta ^| findstr /C:">rdp-tcp#"') do set RDP_SESSION=%%i
:: Strip the >
set RDP_SESSION=%RDP_SESSION:>=%
tscon %RDP_SESSION% /dest:console
Solution 3
glenviewjeff's answer got me most of the way there, but the session id is not always 1. If you try to disconnect the listening or console session like this you'll get an "Error 7045" - requested session access is denied, or if the session id doesn't exist a SessionID not found error.
I made a small batch file to pull out the current session. As I did this on Windows XP I needed to qwinsta rather than query session to figure out the current ID. This batch file uses unix command line utilities, I use Gnu on Windows (https://github.com/bmatzelle/gow/downloads) to have access to these. It pulls out the current session by searching for a ">" sign and then reassigns it back to the console session.
for /f %%i in ('qwinsta ^| grep "^>" ^| awk "{print $4}"') do set VAR=%%i
tscon %var% /dest:console
I needed this for a machine that is connected to a Fujitsu IX500 scanner, the scanner only scans if the screen is not on the user name / signon selection screen in Windows which is what you get when you log off or disconnect a session normally. As the machine runs without a screen I want to be able to connect via rdp, but if I did that I couldn't use the hardware scan button until I logged in manually or restarted. The batch file above solves this problem.
Related videos on Youtube
glenviewjeff
Updated on September 18, 2022Comments
-
glenviewjeff over 1 year
After I am finished with a remote desktop connection, I'd like to be able to restore the remote desktop to the local console so that the user doesn't have to re-enter the password and log back in.
How can I create a desktop shortcut to do this?
-
J-D almost 9 yearsvery welll done :)
-
Helder Magalhães over 8 yearsHere's my version of, optimized to a one-liner in order to be shortcut-friendly:
%windir%\system32\cmd.exe /c "for /F "tokens=1 delims=^> " %i in ('""%windir%\system32\qwinsta.exe" | "%windir%\system32\find.exe" /I "^>rdp-tcp#""') do "%windir%\system32\tscon.exe" %i /dest:console"
It replaces>
environment variable replacement with additionalfor
parsing trickery, as well as addscmd
options (for the shortcut). When combined with a proper icon (I used the log off icon fromShell32.dll
), it gets similar to this. -
James Esh almost 6 yearsI had to make this shortcut run as administrator for it to work. Right click > Properties > Advanced
-
rominator007 over 4 yearssince we stumbled upon that because of this issue: keep in mind that when using the work-around with tscon that the session stays open without lock! that means that anyone that has a connection to the console (for example via virtual machine manager console or vsphere) can use the open session even from another user without logging in. So in the used script there should also be a session lcok