Beef up your admin scripts with these extra tools

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 Run method 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.



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 practise 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.

TechRepublic is the online community and information resource for all IT professionals, from support staff to executives. We offer in-depth technical articles written for IT professionals by IT professionals. In addition to articles on everything from Windows to e-mail to firewalls, we offer IT industry analysis, downloads, management tips, discussion forums, and e-newsletters.

©2003 TechRepublic, Inc.

Advertisement

Talkback 0 comments

Sponsored content

Power Centre - Content from our premier sponsors

Blogs

  • Chris Duckett Get extensions going in Firefox, redux
    Previously on Null Pointer we looked at getting extensions working in Firefox betas, and that was great until the fine folks at Firefox changed their minds.
  • Array How reliable is IP telephony?
    Have you ever heard a weird kind of hissing, crackling or popping noise when calling someone on an IP telephony line? How rare is the phenomenon these days?
  • Array Forget the NBN, 100Mbps is already here
    Telstra and TransACT will shortly begin offering 100Mbps broadband to many customers. By moving early, the companies have not only raised the bar for Australia's broadband services, but thrown down a challenge to a government that now faces increased pressure to deliver the NBN as promised.
  • More blogs »

Tags