Logon Script GPO - Map Network drives and printers

Hi to all, I am new to VBScript, I am needing to write a GPO logon script in order to map network drives automatically and printers to my clients.

Allready find how to map basically some share to a drive letter but i couldnt find how to map like this:

I need to map \\\Data\Users\%username% but i cant do that in Vbscript, so i need to find the user who is logging in, place that in a variable and append it to de path.

2) I need to automatically add printers based on the OU the user is. This I dont know how to do it.

Thanks for any help you could give me, cheers!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Justin OwensITIL Problem ManagerCommented:
Here is an excellent article teaching the points of using VBScript to map drives based on username:


For your Printers based on OU, it seems to me the easiest way to do that would be create a GPO and link it to that OU, rather than having one massive script to handle all OUs.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jzamitAuthor Commented:
Thanks Dr Ultima, but I allready used that web page  from computerperformance and it keeps failing, i copy pasted that code, changing the names to match my shares and etc, but keeps failing.  Thanks for your advice!

Justin OwensITIL Problem ManagerCommented:
Can you paste in the code you are using?  It should be pretty easy to help fine tune it for you.
The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

jzamitAuthor Commented:
Of course here is what i copy pasted and changed , note that nothing is written for printers because i couldn`t fix my first problem...

' ----------------------------------------------------' 
Option Explicit
Dim objNetwork 
Dim strDriveLetter, strRemotePath, strUserName
strDriveLetter = "J:" 
strRemotePath = "\\srv-dc01\datos\usuarios" 

' Purpose of script to create a network object. (objNetwork)
' Then to apply the MapNetworkDrive method. Result J: drive
Set objNetwork = WScript.CreateObject("WScript.Network") 
' Here is where we extract the UserName
strUserName = objNetwork.UserName 
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath _
& "\" & strUserName

' Extra code just to add a message box
WScript.Echo " Launch Explorer, check: "& strDriveLetter

' End of MapNetworkDrive Example logon script.

Open in new window

Can you use Active Directory to determine users' home folders? (Profiles tab.)

And then, as suggested by DrUltima, use GPO to map printers?
Ron MalmsteadInformation Services ManagerCommented:
First install "Group Policy Management Console"... if you don't already have it.
Once intalled, goto start > run ...type ... GPMC.MSC   ..click ok.

For mapping drives..

NET USE U: "\\\Data\Users\%username%"   ..is perfectly valid and will work on a logon script via a simple batch file.  Create a logon script in a GPO object and link it too all your user gpo's.

For installing printers.....
You can create  a seperate GPO for each OU that you want to map a specific printer.

So for example...you have accounting OU...create a GPO called...   Accounting Printers.. and link it to the accouting OU.

Also, I\in the "security filtering" section of the Group policy management console... you can remove "authenticated users", and instead put "accouting users"...and this will make sure the script only runs for accounting members.  You can simply leave it as the OU membership as well.

In this GPO..create a logon script *.bat file.... and put the following line in it.
CSCRIPT %SYSTEMROOT%\SYSTEM32\PRNMNGR.VBS -ac -p \\servername\hp1300

PRNMNGR.VBS - is a vb script that microsoft put in your system32 folder, and it is used to query, map, and remove printers.
jzamitAuthor Commented:
Thansk for your help, I have working  the vbs code for mapping to  \\srv-dc01\datos\usuarios\"actualuser" to j, I think it was some copy paste issue that was having me in trouble.

Now I need the printers thing, and i will try to use, GPO in order to accomplish that task. i try it now and post what happend, thanks to all for your help!


jzamitAuthor Commented:
xuserx2000: Thanks for your help, I try what you said for the printers, and works fine, but how could I add more printers and set one for default and others optional use?

I used:
CSCRIPT %SYSTEMROOT%\SYSTEM32\PRNMNGR.VBS -ac -p \\servidor\laserjet

Thanks again!
Ron MalmsteadInformation Services ManagerCommented:
You can add more printers using the same method.
To get a list of commands you can use with that script  ...type the following...

Default a printer...
First... list all the printers...

To default the printer...  type the following command line + the printer name that shows in the printers listed from the command above.  If the name has spaces be sure to enclose it in quotes...


CSCRIPT %SYSTEMROOT%\SYSTEM32\PRNMNGR.VBS -t -p "\\servidor\laserjet"


CSCRIPT %SYSTEMROOT%\SYSTEM32\PRNMNGR.VBS -t -p "\\servidor\laserjet 1300"
jzamitAuthor Commented:
Thanks for all that help me out! Cheers, jzamit!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.