• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
Writing Terminal Service BasedScripts
Being a child of the 1980s, I pretty much grew up with DOS. As such, I became very comfortablewith DOS commands, and still work extensively with the Windows Command Prompt to this day.Many administrators simply assume that the Windows Command Prompt is a relic that’s left over from the 1980s. In fact, I’ve got a good friend in Kentucky who has been making fun of me for wellover a decade for my various Command Prompt exploits (yes, I’m talking to you Shamir).There is a lot more to the Command Prompt than meets the eye. As Windows has evolved, so toohas the Command Prompt. Sure, most of the original DOS commands are still supported, butMicrosoft has added countless new commands over the years. Many of these commands arenetworking related, and some are specifically related to the Windows Terminal Services.In this article series, I am going to introduce you to some of the commands that are the most usefulto terminal service administrators. Some of the commands that I will be discussing are not directlyrelated to the terminal services, but are still very useful in a terminal service environment. Other commands are specifically related to the terminal services. My plan is to spend the next severalarticles in this series introducing you to some various commands, and demonstrating how thosecommands work. Later in the series, I will show you how to use the various commands to createautomated scripts.
The Change Logon Command
The Change Logon command allows you to enable or disable session logins from the CommandPrompt or from an automated script. One way that I have seen this command used in the real worldinvolved a company which needed to lock the users out of a particular server for a few hours eachnight so that various maintenance tasks could be performed. The administrator of that particular company developed a script that disabled session logons, ran the maintenance tasks, and then re-enabled logons.The syntax for this command is very simple. Simply enter the CHANGE LOGON command,followed by one of three switches:
/QUERY
Tells you whether session logons are currently enabled or disabled
/ENABLE
Enables session logons
/DISABLE
Disables session logonsIf you look at Figure A, you can see the Change Logon command in action. In the figure, I haveentered the CHANGE LOGON /? command so that you can see the command syntax, and then Ihave entered the CHANGE LOGON /QUERY command, so that you can see the query’s output.
 
Figure A:
The CHANGE LOGON command allows you to enable or disable session loginsSome environments do not support the use of commands that are made up of more than one word(IE: Change Logon). As such, Microsoft has created a single word version of this command. Thesingle word command is: CHLOGON. The syntax works exactly the same whether you use theCHLOGON or Change Logon.
The Change Port Command
The Change Port command is quickly becoming obsolete, but since there are some organizationsthat could still benefit from using this command, I wanted to go ahead and show it to you.The idea behind the Change Port application is that some legacy applications (particularly DOS based applications) are hard coded to use specific serial ports. This can be a real problem if a particular port is already in use, or if it simply does not exist. For example, what happens if anapplication is coded to use COM2, but the machine only has one serial port?The Change Port command can be used to remap serial ports. For example, if an application is hardcoded to use COM2, but the machine only has a single serial port, the port mapping can be changedso that calls to COM2 are redirected to COM1.There are three different things that you can do with the Change Port command. Your first option isto remap a serial port. You can do so by using the portx=porty parameter. For example, if youwanted to redirect calls from COM2 to COM1, you would use the following command:
CHANGE PORT port2=port1
Another thing that the Change Port command allows you to do is to delete a port mapping. To do so,simply follow the Change Port command with the /D switch and the port number. For example, if you wanted to delete the mapping for Port 2, you would enter the following command:
Change Port /D port2
The Change Port command also supports the use of the /Query switch. This allows you to view thecurrent port mappings. The interesting thing about the /Query switch is that it reveals some
 
inconsistencies between Windows versions. In my lab environment, when I ran the Change Port/Query command on a machine that was running Windows Server 2003, and that did not containany physical serial ports, I received a message indicating that no port mappings exist. When I triedthe same thing on a machine that was running Windows Vista, the command revealed the mappingsshown in Figure B.
Figure B:
The Change Port /Query command reveals the machine’s serial port mappingsLike the Change Logon command, there is also an abbreviated version of the Change Portcommand. The abbreviated version of this command is CHGPORT.
The Query Session Command
One of the most simple terminal service related commands is also one of the most useful. TheQuery Session command can be entered without any additional parameters. Upon doing so,Windows will provide you with information about all of the sessions that are currently attached tothe server. As you can see in Figure C, Windows tells you the session name, the name of the user who is logged in through the session, the session ID number, whether or not the session is active,and the type of session.
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...