Reader to Reader - 19 Apr 2000
This month, one scripting solution is provided: Create a Universal Logon Script
April 19, 2000
[Editor's Note: Email your scripting solutions (400 words or less) to Reader to Reader at [email protected]. Please include your script and phone number. We edit submissions for style, grammar, and length. If we print your contribution, you receive $100.]
I recently found several shell scripting commands and utilities that let me create a universal logon script, UniLogon.bat, for clients running Windows NT 4.0, Windows 9x, Windows for Workgroups (WFW) 3.11, or MS-DOS Network Client 3.0 (herein referred to as simply DOS). UniLogon.bat has five sections: Detect OS, Environment Variables, All Users, For Selected Groups, and Append Path.
Detect OS. This section detects the OS version, sets several environment variables used later in the script, copies OS-specific files locally, and runs OS-specific commands. To detect the OS version, I used several shell commands, including the Ver command, which displays OS version information. I piped the Ver command's output through the Find command, looking for strings such as Windows 98 and Windows 95 to detect the OS.
To set the master environment throughout the script I used four utilities:
For NT clients, I used setx.exe, which you can find in the Microsoft Windows NT Server 4.0 Resource Kit.
For Win9x clients, I used winset.exe, which you can find in the Win9x CD-ROM. Winset.exe sets only the master environment, not the current environment. To use winset
.exe in a script, you must first use the Set command.For DOS clients, I used setw.exe, an executable in the 16-bit KiXtart utility that you can download from the KiXtart Archive Web site (http://netnet.net/~swilson/kix). Be sure to read the file setw.txt before you use the utility. I used the Switch variable to take care of the lack of a /persistent switch for the Net Use command on Win9x.
For WFW clients, I used setw.exe in conjunction with vxd.386, which is also in the 16-bit KiXtart utility. I added code to uppercase the WinDir variable name so that WFW can use it.
Environment Variables. To set the network environment variables for the non-NT clients, I used putinenv.exe, which you can download from the FTP Web site at ftp://ftp.winmag.com/dist/wm/wmfiles/9602feb/putenv.zip. This utility's L switch puts LanManager information in the environment. To create the value for the LogonServer variable, I used the utility's D switch to obtain the server and share names for the Z drive, which non-NT clients map to.
Because the syntax for setx.exe differs from the syntax of the other utilities, you don't need to set the network environment variables for the NT clients. (However, you might need to add NT-specific variables in the other sections.) Instead, you can skip to the All Users section.
All Users. This section synchronizes the time and sets the drive mappings. For time synchronization in the NT and Win9x clients, I used nettime.exe in conjunction with rtzone.exe, which nettime.exe needs to preserve time zone differences. You can find both utilities in the NT resource kit. For time synchronization in the DOS and WFW clients, I used the Net Time command.
To set the drive mappings for all the clients, I used the Net Use command and the unuse.exe utility. Unuse.exe, which you can find in the LanManager Resource Kit on the TechNet Client Utilities CD-ROM (March 1998 or earlier), deletes multiple mappings with one command.
For Selected Groups. This section tests for group membership. For NT clients, I used the ifmember.exe utility in the NT resource kit. For non-NT clients, I used the ingroupr.exe utility, which you can find in the LanManager resource kit. Ingroupr.exe requires a server to query. Both utilities can query for global groups only.
Append Path. This section appends the existing path with common-path and group-specific additions. I used the Path command to append the information for both NT and non-NT clients.
You can find UniLogon.bat in the Code Library on the Win32 Scripting Journal Web site at http://www.win32scripting.com. To use this script, you need to customize the environments and paths.
—Michael Murgolo
[email protected]
About the Author
You May Also Like