Windows network and logon scripts

Learn more about logon scripts, what you can use them for, and how to create them.

Windows network and logon scripts
Barrie Sosinsky

Whenever your users or members of a workgroup logs onto their workstations connected to a Windows domain, their options can be initialized in the user environment with logon scripts. You create the scripts with a text editor, and you must save them in specific directories depending upon whether us are using Windows NT 4.0 server or Windows 2000 Server. If you are using Windows NT, you should save the logon script on a primary domain controller in the winntsystem32replimportscripts. If you use Windows 2000, you must save the script on any domain controller in the directory winntsysvoldomainscripts.

Logon scripts can use Windows environmental variables. They can call other scripts or executable programs. They can also map network drives, initialize various options, or start background processes. If you are unfamiliar with logon scripts, check out Simplifying network options through logon scripts on the Microsoft Technet site.

If you are using Windows 2000 you will find information in the Server Documentation help files. A simple example of a logon script is one that maps network drive, network printers, and synchronizes the users' workstations with time servers. Try the following example from a command prompt:

		Net use y: reliantdata
		Net use LPT1: reliantprinter1
		Net time reliant /set/yes
This example maps drive Y: on the local machine to a network share called data on the main server, RELIANT. There is also a map to printer 1` to LPT1 on the local PC. The time setting is synchronized on the PC with the timeserver, also RELIANT.

When you have tasks that need to be done by some users and not others you can address that by using conditional statements. You can run specific commands for a user or group. The following examples also entered from the command prompt demonstrate this:

	If %USERNAME%=Administrator net use z: reliantadmtools
	If ifmember.exe "HR" net use t: relianthr

The first example maps the drive admtools only to the user Administrator. The second example maps a share called hr to the Human Resource Dept, based on the output of a tool called ifmember.exe. This tool is found in the Microsoft Windows 2000 Resource Kit.

While space does not allow for lengthy examples, check out the resources mentioned above for more examples of logon scripts. If you are comfortable with writing scripts, try a few of your own. Some very useful variables are: %USERNAME%; %USERDOMAIN%; % HOMEDRIVE%; %HOMEPATH%; $OS%; %HOMESHARE%; and %PROCESSOR%. Although self-explanatory, you will find these variables of great use in writing logon scripts.


Barrie Sosinsky (barries@killerapps.com)is president of consulting company Sosinsky and Associates (Medfield MA). He has written extensively on a variety of computer topics. His company specializes in custom software (database and Web related), training and technical documentation.

Did this tip float your boat? If so, why not let us know? E-mail us and sound off. Or visit our tips page and rate this, and other, tips.

Related Book

Windows NT/2000 ADSI Scripting for System Administration
Author : Thomas Eck
Publisher : Macmillan Technical Publishing
Published : Mar 2000
Summary:
This book will provide system administrators with solutions to automate and simplify the configuration and management of their networks. The author will present expert tips, code development and proven in real-world enterprise environments.


This was first published in April 2001

Dig deeper on Working With Servers and Desktops

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchSDN

SearchEnterpriseWAN

SearchUnifiedCommunications

SearchMobileComputing

SearchDataCenter

SearchITChannel

Close