Tip

Windows network and logon scripts

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

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.