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.

1)
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 \\192.168.2.2\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!

jzamitAsked:
Who is Participating?
 
Justin OwensConnect With a Mentor ITIL Problem ManagerCommented:
Here is an excellent article teaching the points of using VBScript to map drives based on username:

http://www.computerperformance.co.uk/Logon/Logon_HomeDirAdv.htm#Example_1_-_MapNetworkDrive_to_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.

DrUltima
0
 
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!

jzamit
0
 
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.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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
WScript.Quit

' End of MapNetworkDrive Example logon script.

Open in new window

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

And then, as suggested by DrUltima, use GPO to map printers?
0
 
Ron MalmsteadConnect With a Mentor Information 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: "\\192.168.2.2\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.
0
 
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!

Jzamit

0
 
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!
Jzamit
0
 
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...
CSCRIPT %SYSTEMROOT%\SYSTEM32\PRNMNGR.VBS /?

Default a printer...
First... list all the printers...
CSCRIPT %SYSTEMROOT%\SYSTEM32\PRNMNGR.VBS -l


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...

Example...

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

 ,Or

CSCRIPT %SYSTEMROOT%\SYSTEM32\PRNMNGR.VBS -t -p "\\servidor\laserjet 1300"
0
 
jzamitAuthor Commented:
Thanks for all that help me out! Cheers, jzamit!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.