Subscribe to Windows IT Pro
July 01, 1999 12:00 AM

NT Command-Script Techniques

Windows IT Pro
InstantDoc ID #5622
Rating: (0)
Simplify administrative tasks

This month, I look at 10 essential Windows NT command-script techniques. Command scripts are ASCII text files that contain a group of NT commands. Command scripts can help you automate administrative tasks, such as creating users or shares or running a backup.

10. Adding comments to a script lets you help others understand what your script does and helps you remember the purpose of older scripts. Use double colons (::) or a Rem statement to add comments to a script.

:: Filename: myfile.bat
rem This batch was created on 03/12/99

9. The Echo command lets you control NT's default echo functionality. By default, NT displays all commands onscreen unless you explicitly turn off the capability. Echo Off turns off all echoing, except those commands that start with Echo. @Echo Off turns off echoing for the command that follows.

@echo off
echo Command file processing is starting

8. The Goto command and tags let you add structure to your command files. Goto branches to the tag that the Goto statement specifies.

goto error
:error

7. Command-line parameters let you give command files flexibility and reusability. For instance, a command file that adds users might accept a username as a parameter so that different users can use the same script. Command-line parameters start with the percent sign (%), followed by the ordinal number of the parameter.

net user %1 /add

6. Environment variables let you retrieve settings from the system's environment and substitute values when the script runs. You use the Set command to create a new environment variable. You use the variable name between % symbols to retrieve the contents of an environment variable.

set user=tempuser
net user %user% /add

Related Content:

ARTICLE TOOLS

Comments
  • smantis
    11 years ago
    Jan 18, 2001

    Great article.

  • Ronald Rysanek
    13 years ago
    Aug 14, 1999

    Great article. Would like to see more inforamtion in this area.

    Can you please tell me what the == means and how they are used.

  • John Klassen
    13 years ago
    Aug 03, 1999

    Great article for a veteran of the UNIX shell! The #1 tip was my favorite on Bourne Shell, but I never figured it out on NT until now. Thanks! -jkk

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.