Network Logon Scripts
Contents
Net use
Connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections. The command also controls persistent net connections.
net use [devicename | *] [\\computername\sharename[\volume]] [password | *]] [/user:[domainname\]username] [[/delete] | [/persistent:{yes | no}]] ` net use devicename [/home[password | *]] [/delete:{yes | no}] ` net use [/persistent:{yes | no}]
`
Login Scripts to Change a User to Home Directory
On the Server
Because a LAN Manager login script cannot contain replaceable parameters, set up your login script like the file below:
NETLOGON.BAT ------------ echo net use s: \\servername\public >c:\local.bat echo net use v: \\servername\apps >>c:\local.bat echo net use r: /home >>c:\local.bat
On Each Workstation
Create a batch file similar to the batch file below:
LOGON.BAT --------- net logon %1 call c:\local.bat cd r:\%1 r:
`
Windows 2003 - netlogon scripts using a batch file
Batch file to map network drives for users
The NETLOGON folder will be created when you run DCpromo. When you run Dcpromo.exe to promote a Windows 2000-based server to a domain controller, a dialog box appears prompting you for a permissions preference. This article describes the available options and the reversal of these choices.
The default Windows login script is located at:
c:\windows\sysvol\sysvol\servername1\scripts and the script file is Windows_LOGIN_SCRIPT.bat. ` network path: \\servername1\netlogon
Create the default batch file, default.bat in the scripts folder
You can create default windows login scripts for individual users to. Then, use the following code in your default.bat to activate them:
\\servername1\netlogon\%username%.BAT
You will have to manually create the new batch file for each user.
Here is the content of one such user batch file:
Rem Batch File for user John Doe NET USE Q: \\servername1\Quickbooks NET USE S: \\servername1\SharedCompany NET USE T: \\servername1\Access
You can map the drives all in the default batch file too.
NET USE M: \\Users Shared Folders\%paulWilson%
http://msmvps.com/blogs/kwsupport/archive/2004/11/03/17830.aspx
`
Samba Example
net use z: \\linux\samba /yes
echo Hello %USERNAME%, welcome to the network! echo You are accessing the network from %COMPUTERNAME% echo And you are running the %OS% os. echo Please wait, authenticating %USERNAME% with the %LANGROUP% domain \\PDC\netlogon\sleep 2 # net use U: \\MY_SERVER\users net use P: \\MY_other_server\public # net use U: /del net use P: /del net use U: \\MY_SERVER\users net use P: \\MY_other_server\public
if you want your net use statements not to show up, precede them with a '@', example:
@net use M: \\server\mp3
If you want the system time of all the workstations to match the primary domain controller (yes, you do...) add this line:
net time \\MY_PDC /set /yes
`
UPDATED NETLOGON NOTES CREATED IN 2007
Use the "yes.txt" trick. It is a way to have the script force an answer of "Y" so it does not prompt the user.
YOUR COMMAND < Yes.txt > NUL
Then you create a text file and put a Y in it. This is also used for netlogon scripts a lot.
It is documented on Microsoft support under netlogon examples:
"Create a file called YES.TXT using any ASCII text editor, such as Edit or Notepad. On the first line, type in the letter Y and press enter."
map del Z: < Yes.txt > NUL
Then go ahead and map your Z drive to the new server share path
`
A VBScript Example of Netlogon
Just so you can see what it looks like compared to using traditional batch files.
Dim wshNetwork Set wshNetwork = CreateObject("Wscript.Network") wshNetwork.MapNetworkDrive "k:", "\\server1\myshare" # PrinterPath = "\\server1\myprinter" PrinterDriver = "HP LaserJet 6P" WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver WshNetwork.SetDefaultPrinter "\\server1\myprinter"
`
More Netlogon Batch File Examples
Example 1
@ECHO OFF call net use z: \\192.168.1.2\zshare datashare /user:datashare /persistent:yes net use P: \\Server1\net.public
Example 2
Which is the correct way to delete a share?
@ECHO OFF call net use z: /del < yes.txt > NUL map del Z: < yes.txt > NUL call net use z: \\192.168.1.11\zshare datashare /user:datashare /persistent:yes
`