Microsoft

Build Your Skills: Beef up your admin scripts with these tools

Describes Microsoft tools that can help you build or enhance administration scripts


In a previous article, I mentioned IFMEMBER.EXE, a valuable Windows Resource Kit tool you can use to refine login scripts. Microsoft also provides a number of other tools that will help you improve your administration scripts. I'm going to show you where to find these tools and introduce a few that you may find useful. I'll also tell you about a particularly handy tool called KiXtart, which you can use to enhance your scripts.

Allen Rouse's previous scripting articles


Running executables in scripts
The utilities that Microsoft provides are command line executable files that come with their own syntax. To use them, you must first know how to run an executable file within a script.

Executing a utility within Windows shell scripts is fairly straightforward. You know that you can execute a command line program at the command prompt. Since shell scripts are basically a series of command line instructions, you can simply include the executable on its own line in the script. If it's not in the default path, just include the path as part of the command line.

For instance, one of the utilities that Microsoft provides is INUSE.EXE, a tool that can replace files that are currently in use by the operating system. To run it, you must specify the name of the source file and the name of the file to be replaced. For example, you might include a line like this in your script:
 
"C:\Program Files\Resource Kit\inuse.exe" f:\test1.dll \\SERVERA\Winnt\System32\test1.dll

It's not quite that easy in Visual Basic Scripting, but it's not too difficult either. First, to run a command line utility with a VBS script, you must access the Runmethod within the WshShell Object. The syntax for that is:
 
Wscript.Run (command, [WindowStyle], [WaitonReturn])

In this case, command is the complete command line utility with parameters, WindowStyle is an optional parameter that controls the style of the command window, and WaitonReturn is either true or false, specifying whether the script should wait until the utility completes processing before continuing with the script. Running INUSE.EXE within a VBS script might look something like this:
 
Set ObjWS = WScript.CreateObject("WScript.Shell")
ObjWS.Run ("INUSE.EXE f:\test1.dll \\SERVERA\Winnt\System32\test1.dll", 0,"true")

Head for the tool shed
So, now that you know how to use these utilities within a script, you need to know where to go to get them. The best place to go is the Windows Resource Kit. Both the Windows NT Resource Kit and the Windows 2000 Resource Kit have the tools. You can also download many of the individual tools here.

The Resource Kits generally provide you with not only the executable file, but also with complete information on how to use the tools, along with examples.

Figure A, for instance, shows the syntax for ADDUSERS.EXE, a command line utility you can use to create users and groups within a script.

Figure A


The Resource Kits conveniently group the tools by functionality, as shown in Figure B. You can use the Search tab if you need to find a specific tool.

Figure B


Table A lists a few of the many Resource Kit tools you might find useful in your scripts for network administration.

Table A
Delprof.exe Deletes user profiles from a Windows 2000 computer
Delsrv.exe Unregisters a service
Regini.exe Edits the registry with a script
Logoff.exe Automatically logs off when used in an unattended installation
Permcopy.exe       Copies share and file permissions from one share to another
Now.exe Stamps current date and time

Also consider KiXtart
The Windows Resource Kits also include a great scripting tool called KiXtart. This tool is a logon script processor and an enhanced batch scripting language developed for Windows by Ruud van Velsen of Microsoft Netherlands. It's free software, but the author calls it CareWare and asks that users donate to a charity in lieu of paying a fee for using it.

You will find documentation for the tool, as well as the actual files for download, at kixtart.org. The manual available for download from this site carries 120 pages of extensive documentation.

The only file required for Windows NT and higher is kix32.exe. With it, you can launch any KiXtart script, which is a text file written in the KiXtart scripting language. The language is neither shell scripting nor VBS, but a separate scripting language with a great deal of functionality. It can process commands based on group membership, and it can be used for mapping drives, editing the registry, manipulating the file system, and a lot more.

Each script file, created with a text editor such as Notepad, is saved with the extension .kix. Let's say you create a file and name it myscript.kix. This script can then be run with a simple command like this:
Kix32.exe myscript.kix

You can execute it at the command prompt or place the command into a Windows shell script.

End sum
Now that you know about all of these great tool resources available to you, you can start using them in your scripts. You will want to take the time to learn them, of course, as well as practice them extensively on a lab network before you use them on a production network. Fortunately, both the Resource Kits and KiXtart have good documentation on syntax and usage.

 

Editor's Picks