Home > SCRIPTING, WINDOWS > Batch file script to map network drive to users

Batch file script to map network drive to users

  • Sharebar

A batch file is a text file containing a series of commands intended to be executed by the command interpreter. When a batch file is run, the shell program reads the file and executes its commands, normally line-by-line.

The following script can be used as a logon script to map a network drive to users home directory (or any directory) on the server or somewhere else.

1- Copy and past the script in a text editor, notepad will dose the job perfectly.
2- Make whatever change in need to suit your purposes. ie; change the server name and the share name to reflect yours.

3- Save the file (any name you like) with extension of .bat, ie: logon.bat
4- You may test it on your local machine by double clicking it, you may assign it to a group or to just a single user within your windows network.

In this example i’ll map three network drives to a user, first one is the user network home drive, 2nd and 3rd are directory within user’s department and Public shard folder respectively.

Tip: If you want to assign the script to multi users to map their home directories you can use the variable %username% instead of a single user’s account, This is true if the name of the home directory of a user is the same as his/her account’s username . ie:

instead of:

net use w: \\server\drives\user1 /PERSISTENT:YES

you may use:

net use w: \\server\drives\%username% /PERSISTENT:YES

And here comes the script:

:: BATCH FILE SCRIPT TO MAP NETWORK DRIVES FOR USERS AT LOGON
:: CREATED BY Rahul.R.S http://rahultweaks.com
net use x: \\server\commonshare\user1 /PERSISTENT:YES
net use y: \\server\Departmentdata\Accounting /PERSISTENT:YES
net use z: \\server\public /PERSISTENT:YES

OR

@ECHO off
net use * /delete
net use w: “\\mars\Resource Share\Common Exchange” /PERSISTENT:YES
net use x: “\\mars\projects” /PERSISTENT:YES
net use y: “\\mars\COMMON_SHARE” /PERSISTENT:YES
gpupdate /force

* your share name with space you just do this net use z:”\\server\user folder” //PERSISTENT:YES

  1. ANN Hoeun
    June 24th, 2013 at 17:22 | #1

    That really help full. Thank you very much

  1. No trackbacks yet.

Uses wordpress plugins developed by www.wpdevelop.com Copy Protected by Chetans WP-Copyprotect.