Monthly Archives: August 2008

CTRL+ALT+DEL in Remote Desktop

CTRL+ALT+DEL = CTRL+ALT+END in remote desktop.

There are a few other shortcut key mappings in Remote Desktop. From the help file:

ALT+[SHIFT]TAB = ALT+PAGE UP/PAGE DOWN/INS
CTRL+ESC = ALT+HOME
ALT+PRINT SCREEN = CTRL+ALT+Keypad Minus
PRINT SCREEN = CTRL+ALT+Keypad Plus

ASCII Characters

Chr Dec Oct Hex Chr Dec Oct Hex Chr Dec Oct Hex
(nul) 0 000 00 + 43 053 2b V 86 126 56
(soh) 1 001 01 , 44 054 2c W 87 127 57
(stx) 2 002 02 45 055 2d X 88 130 58
(etx) 3 003 03 . 46 056 2e Y 89 131 59
(eot) 4 004 04 / 47 057 2f Z 90 132 5a
(enq) 5 005 05 0 48 060 30 [ 91 133 5b
(ack) 6 006 06 1 49 061 31 \ 92 134 5c
(bel) 7 007 07 2 50 062 32 ] 93 135 5d
(bs) 8 010 08 3 51 063 33 ^ 94 136 5e
(ht) 9 011 09 4 52 064 34 _ 95 137 5f
(nl) 10 012 0a 5 53 065 35 ` 96 140 60
(vt) 11 013 0b 6 54 066 36 a 97 141 61
(np) 12 014 0c 7 55 067 37 b 98 142 62
(cr) 13 015 0d 8 56 070 38 c 99 143 63
(so) 14 016 0e 9 57 071 39 d 100 144 64
(si) 15 017 0f : 58 072 3a e 101 145 65
(dle) 16 020 10 ; 59 073 3b f 102 146 66
(dc1) 17 021 11 < 60 074 3c g 103 147 67
(dc2) 18 022 12 = 61 075 3d h 104 150 68
(dc3) 19 023 13 > 62 076 3e i 105 151 69
(dc4) 20 024 14 ? 63 077 3f j 106 152 6a
(nak) 21 025 15 @ 64 100 40 k 107 153 6b
(syn) 22 026 16 A 65 101 41 l 108 154 6c
(etb) 23 027 17 B 66 102 42 m 109 155 6d
(can) 24 030 18 C 67 103 43 n 110 156 6e
(em) 25 031 19 D 68 104 44 o 111 157 6f
(sub) 26 032 1a E 69 105 45 p 112 160 70
(esc) 27 033 1b F 70 106 46 q 113 161 71
(fs) 28 034 1c G 71 107 47 r 114 162 72
(gs) 29 035 1d H 72 110 48 s 115 163 73
(rs) 30 036 1e I 73 111 49 t 116 164 74
(us) 31 037 1f J 74 112 4a u 117 165 75
(sp) 32 040 20 K 75 113 4b v 118 166 76
! 33 041 21 L 76 114 4c w 119 167 77
" 34 042 22 M 77 115 4d x 120 170 78
# 35 043 23 N 78 116 4e y 121 171 79
$ 36 044 24 O 79 117 4f z 122 172 7a
% 37 045 25 P 80 120 50 { 123 173 7b
& 38 046 26 Q 81 121 51 | 124 174 7c
' 39 047 27 R 82 122 52 } 125 175 7d
( 40 050 28 S 83 123 53 ~ 126 176 7e
) 41 051 29 T 84 124 54 (del) 127 177 7f
* 42 052 2a U 85 125 55

Command line completion in Windows (like bash)

Here is the trick to command line completion in Windows. Open regedit and find this key:

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar

By default the value is for CompletionChar is 0, set it to 9 (for <tab>) and you will have command line completion! This allows you to use <tab> to complete directory and file names so instead of typing C:\ThisIsAReallyLongDirectoyName, you can type C:\Th<tab> and the DOS box will complete the name for you.

One caveat. You must open a new DOS (CMD) window to see the effect. A window that is already open when you make the change will not show it.

P.S. – You can also change this setting using a GUI interface in XP if you install the TweakUI "power toy".

Return value of a command in sh/bash

The return value of a command executed in a bash shell is put into the variable "$?". For example:

#!/bin/sh
ls gobbledygook
res=$?
if [ "$res" -ne 0 ]
then
echo ls returned $res
fi

Unless you have a file named "gobbledygook" in the current directory, this should print "ls returned 2". Note that I had to save the value of "$?" into my own var (res) immediately after the call to ls. Otherwise the very next command (if) would overwrite the value.

Manage Remote Desktop Sessions from the client

Ever try to log into a Windows machine using remote desktop and get the message "The terminal has exceeded the maximum number of allowed connections"? Well, this is a quick primer on how to determine who is using those connections and how to free up the inactive or locked ones. Essentially, there are two commands you need to know; qwinsta and rwinsta.

qwinsta (short for query windows instance) allows you to view the status of remote desktop (RDP) session for a given machine. The basic syntax you will want to remember is qwinsta /server:<server name>. For example:

c:\>qwinsta /server:fs-build
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console 0 Conn wdcon
rdp-tcp 65536 Listen rdpwd
jqian 4 Disc rdpwd
rdp-tcp#27 cmckeachie 5 Active rdpwd

Here I ran qwinsta to see who is connected to fs-build. As you can see Jason and Craig are using the two remote sessions (and IDs 4 and 5 respectively). You will also see the console (on ID 0) and something called rdp-tcp (on ID 65536). The console is always there and represents the physical desktop window if you are sitting in front of the machine itself. The rdp-tcp guy represents the process that is listening for remote connection requests.

Because we do not pay for terminal server licenses, we have a maximum of 2 connections per machine (1 if it’s windows XP). So, if you want to log in to fs-build, you need to track down Jason or Craig and see when they will be done.

Now, there is one more thing you may notice in the output from qwinsta, the "STATE". You can see that Craig is "Active" but Jason is "Disc" (or disconnected). Basically, it looks like Jason was logged in but his session expired so even though he is logged in, he is not connected to the session. This happens when you lose connectivity to the machine (network down) or when you close the connection with out logging out of the machine. Let me just say, you should ALWAYS log off when you are done with remote desktop. It’s not enough to just click the close gadget on the window!

Ok, so let’s say we talked to Jason and he is in fact done with his session on fs-build. Now we need our second command, rwinsta.

rwinsta (short for reset windows instance) allows you to forcibly quit an RDP session on a given machine. The basic syntax you will want to remember is rwinsta /server:<server name> &#60ID>. For example:

c:\>rwinsta /server:fs-build 4

This command resets (or logs out) Jason’s session on fs-build. Note I had to use the ID for his session, not his username. This can take a while depending on how much he did during his session or how many things he left running. Once, the command returns (it does not print status or anything), I can verify that there is now an open connection by once again using qwinsta.

c:\>qwinsta /server:fs-build
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console 0 Conn wdcon
rdp-tcp 65536 Listen rdpwd
rdp-tcp#27 cmckeachie 5 Active rdpwd

And I see Jason’s session is in fact closed.

So, qwinsta and rwinsta are pretty handy but please remember, rwinsta is powerful but it comes with responsibility. If you are an administrator on the machine you remote desktop into it is possible to reset just about anyone’s session. Make sure you check with the person before you do this. Don’t assume it's ok to reset a "Disc" session. That person may have a valid reason for leaving the session running (testing over the weekend for example or just being accidentally disconnected due to network hiccup).

Ok, if you’re bored, feel free to stop here. For those of you who are not asleep yet, there is a third command you may want to know about; tscon.

tscon (short for terminal session connect) is used to switch from one session to another on the remote (or local) machine. Basically, you log in to a remote machine and then use tscon to connect to another session. The syntax to remember is:

c:\>tscon <ID>

Why would you use this? Well, suppose you are connected to a remote machine and you get disconnected. If you try to reconnect, the RDP client is supposed to be able to connect you to your previous session but it often does not. If you have stuff running in that other session and you don’t want to start over, it’s tscon to the rescue. Once you are logged in using a second session, you would open a command prompt and use qwinsta to figure out your old session id. Then you use tscon to connect to that old session. Please remember, you are now using two sessions (our maximum for any one machine) on the remote machine so please complete your work quickly and log off. Also, you should do a little clean up. Once you log off of your original session, your second session is still out there so please be kind and kill it with rwinsta (or log back into it and out again using RDP client)!

P.S. – There is a GUI app that makes this stuff a lot easier but it is not usually found on your client machine (XP for me). Terminal Services Manager is the tool. There are other aspects to the three commands discussed in this email. I just outlined the ones you will probably find the most useful. Use "<command> /?" if you want to learn more.