|
Creating & Running a Logon Script |
Last Updated:
05/05/2009 |
Goal
- Using a logon script to automatically map a drive when a user logs on.
- Scripts can be DOS .BAT files or .VBS files.
The NET USE Command
- Net Use is a command line operation that can be used to map a network
drive or disconnect a previously mapped network drive.
- It can be executed from a Command Prompt (DOS box), or it can be executed
from a script batch file (a .BAT file).
- Syntax for mapping a network drive:
NET USE devicename \\computername\sharename /PERSISTENT:{YES|NO}
- devicename - are any unused drive from D: through Z:
- persistent - yes means "reconnect at logon" and no
means don't "reconnect at logon"
- Examples:
NET USE U: \\A247Server\data\users /PERSISTENT:NO
maps the U: drive to the users share and without reconnecting
at next logon
NET USE F: \\A247Server\data /PERSISTENT:YES
maps the F: drive to the data share and reconnects F: to it
at subsequent logons
- If you want/need to learn more about NET USE, start a Command Prompt and
type the command:
NET HELP USE
- If you place a NET USE command in a .BAT file (a batch file), then the
batch file can be executed as a user's logon script and automatically map a
network drive each time the user logs on. Multiple network drives can
be mapped if the batch file contains more than one NET USE command.
.BAT files are plain ASCII text files and can be created and edited with any
editor.
Using Group Policy to Set Up a Logon Script - 
- In a previous lab we created the shared folder SWUnitFolder that it could
be shared by all the users in the SoftwareUnit OU.
- The problem we need to solve is: how to (in one spot) automatically
create a drive mapping to this shared folder for all the users in the
SoftwareUnit OU.
|

Shared Folder
|
- The answer is to set a Group Policy for the SoftwareUnit OU
- A logon script is one of the policies that we can set in a Group
Policy Object (GPO).
- A GPO applied to an OU will have an effect on all users in the OU
(and no one else).
- Therefore, by setting up a logon script in a GPO
linked to the SoftwareUnit OU, we can give every user in the OU a logon
script.
- If the logon script is a .BAT file that executes a NET USE command,
then we can make it so that all SoftwareUnit OU users will automatically
have a drive mapped to the SWUnitFolder shared folder.
Working on the Server Computer
Edit the SoftwareUnitGPO
- Click: Start | Administrative Tools | Group Policy Management
This will bring up the Group Policy Management Tool.
- Navigate To: Forest: bailiwick.local | Domains | bailiwick.local
| Group Policy Objects | SoftwareUnitGPO
- Right Click: the SoftwareUnitGPO
This will bring up the context menu.
- Click: Edit...
This will bring up the Group Policy Management Editor.
- Navigate to:
User Configuration | Policies | Windows Settings | Scripts
(Logon/Logoff) See screen shot to the right.
- Right Click:
choose: Properties.
This brings up the "Logon Properties"
dialog (not shown here).
- Click: Add... button
This brings up the
"Add a Script" dialog (not shown here).
- Click the Browse button.
This brings up the "Browse"
dialog (see below)
 |
 |
- Right Click: in the Browse dialog's white area (underneath "Name").
This brings up the context menu.
- Choose: New | Text Document
Name the document: script.bat
- Right Click: script.bat and choose Edit from the context menu.
- Add one line to the file:
- Utilize the NET USE command that maps the S: drive
to \\A247Server\SWUnitFolder shared folder
- Set persistence to no.
NET USE S: \\A247Server\SWUnitFolder /PERSISTENT:NO
- Save the file and exit back to the Browse dialog.
- Make sure the new script.bat file is selected and click OK, this will take
you back to the "Add a Script" dialog.
- In the "Add a Script" dialog, script.bat should be the only file
listed, click OK to exit. This will take you back to the "Group
Policy" administrative tool. Close this window, which should
return you to the "Active Directory Users and Computers"
administrative tool.
Working on the Client Computer
Test the SoftwareUnit OU's Group Policy
- On your client machine, logout and then logon as any one of the users in the SoftwareUnit OU.
- Use Windows Explorer to see if the S: drive has been automatically mapped
to the shared SWUnitFolder folder.
Also, the H: drive should still be mapped
to the user's home folder.
- Do something on the S: drive (e.g., create a file) to make sure the user
still has the rights to this shared folder.
- Logout and logon as lowdog and see if the S: drive automatically gets
mapped.
Finally
- Show me that the S: drive is mapped correctly for one of the SoftwareUnit
OU users.