Solved

SBS2003 - Mapping Network Drives via VBS

Posted on 2010-08-27
18
744 Views
Last Modified: 2012-06-27
I have a script that I pulled from the net which simply maps a printer for a user. I wish however to add four mapped drives to this script in the simplest way possible. I am not interested in security groups or anything like that, just straight forward mapping of 4 network drive locations

The script I am currently using for the printer that I wish to add to is

Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\SATURN\KM-MC4695MF"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
WScript.Echo "Check the Printers folder for : " & strUNCPrinter

WScript.Quit

Thanks is advance
0
Comment
Question by:NorthstarIT
  • 10
  • 5
  • 3
18 Comments
 
LVL 4

Expert Comment

by:acstechee
Comment Utility
Hi

Normally I would just use a login script to map the network drives using a net use command?
 Use a batch file with something like 'net use z: \\server\share'

I'm sure it could be done using vbs

Thanks

Gareth
0
 

Author Comment

by:NorthstarIT
Comment Utility
I too would use a batch file however this needs to work with the printer mapping too which is in VBS
0
 
LVL 4

Expert Comment

by:acstechee
Comment Utility
How about adding this to your vbs:

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "Z:" , "\\server\share"

?

0
 

Author Comment

by:NorthstarIT
Comment Utility
Can I multiply the above code x 4, one for each drive?
0
 
LVL 5

Expert Comment

by:piji
Comment Utility
Just add this command

objNetwork.mapnetworkdrive "z:", "\\server\share"

Net use command is used for bath file.
0
 
LVL 5

Assisted Solution

by:piji
piji earned 200 total points
Comment Utility
Absolutely you can like these:

objNetwork.MapNetworkDrive "Z:" , "\\server\share"
objNetwork.MapNetworkDrive "U:" , "\\server\company"
objNetwork.MapNetworkDrive "W:" , "\\server\clientapps"
0
 

Author Comment

by:NorthstarIT
Comment Utility
What would be the command to delete a network drive before using the objNetwork.mapnetworkdrive "z:", "\\server\share"
?
0
 
LVL 4

Expert Comment

by:acstechee
Comment Utility
objNetwork.RemoveNetworkDrive "Z:" "\\server\share"
0
 

Author Comment

by:NorthstarIT
Comment Utility
I am using the following code and it is erroring at line 6

Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\SATURN\KM-MC4695MF"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.RemoveNetworkDrive "k:" "\\saturn\applications"
objNetwork.mapnetworkdrive "k:", "\\saturn\applications"
objNetwork.RemoveNetworkDrive "s:" "\\saturn\swap"
objNetwork.mapnetworkdrive "s:", "\\saturn\swap"
objNetwork.RemoveNetworkDrive "t:" "\\saturn\tc\client folders"
objNetwork.mapnetworkdrive "t:", "\\saturn\tc\client folders"
objNetwork.RemoveNetworkDrive "z:" "\\saturn\data"
objNetwork.mapnetworkdrive "z:", "\\saturn\data"
WScript.Quit

Any thoughts anyone?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Expert Comment

by:acstechee
Comment Utility
you might need a comma in between the drive letter and location. Sorry, my bad.
0
 

Author Comment

by:NorthstarIT
Comment Utility
No problem, now using  the below and it is coming up with Line 6 char1 type mismatch

Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\SATURN\KM-MC4695MF"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.RemoveNetworkDrive "k:", "\\saturn\applications"
objNetwork.mapnetworkdrive "k:", "\\saturn\applications"
objNetwork.RemoveNetworkDrive "s:", "\\saturn\swap"
objNetwork.mapnetworkdrive "s:", "\\saturn\swap"
objNetwork.RemoveNetworkDrive "t:", "\\saturn\tc\client folders"
objNetwork.mapnetworkdrive "t:", "\\saturn\tc\client folders"
objNetwork.RemoveNetworkDrive "z:", "\\saturn\data"
objNetwork.mapnetworkdrive "z:", "\\saturn\data"
WScript.Quit
0
 

Author Comment

by:NorthstarIT
Comment Utility
No problem, now using  the below and it is coming up with Line 6 char1 type mismatch

Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\SATURN\KM-MC4695MF"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.RemoveNetworkDrive "k:", "\\saturn\applications"
objNetwork.mapnetworkdrive "k:", "\\saturn\applications"
objNetwork.RemoveNetworkDrive "s:", "\\saturn\swap"
objNetwork.mapnetworkdrive "s:", "\\saturn\swap"
objNetwork.RemoveNetworkDrive "t:", "\\saturn\tc\client folders"
objNetwork.mapnetworkdrive "t:", "\\saturn\tc\client folders"
objNetwork.RemoveNetworkDrive "z:", "\\saturn\data"
objNetwork.mapnetworkdrive "z:", "\\saturn\data"
WScript.Quit
0
 
LVL 5

Expert Comment

by:piji
Comment Utility
You get error message because if there is no "K:", it couldn't remove. it. Why you need to remove the drive?
0
 

Author Comment

by:NorthstarIT
Comment Utility
I just found it more reliable, certainly when using the batch file net use method to ensure that it gets mapped properly.

I will try it withouth the remove command
0
 

Author Comment

by:NorthstarIT
Comment Utility
Took out the remove and now I get the error local device name is already in use

0
 

Author Comment

by:NorthstarIT
Comment Utility
This is fine if that user has never logged onto a specific machine however if they already have used that machine I don't want them to get a logon error
0
 
LVL 4

Accepted Solution

by:
acstechee earned 300 total points
Comment Utility
Hi

Sorry, remove network drive doesn't need a path. ie.
Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\SATURN\KM-MC4695MF"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.RemoveNetworkDrive "k:"
objNetwork.mapnetworkdrive "k:", "\\saturn\applications"
objNetwork.RemoveNetworkDrive "s:"
objNetwork.mapnetworkdrive "s:", "\\saturn\swap"
objNetwork.RemoveNetworkDrive "t:"
objNetwork.mapnetworkdrive "t:", "\\saturn\tc\client folders"
objNetwork.RemoveNetworkDrive "z:"
objNetwork.mapnetworkdrive "z:", "\\saturn\data"
WScript.Quit

Sorry, again, my bad!
0
 

Author Closing Comment

by:NorthstarIT
Comment Utility
Thank you both. I hope you accept why I have split the points
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Written by Glen Knight (demazter) as part of a series of how-to articles. Introduction One of the biggest consumers of disk space with Small Business Server 2008(SBS) is Windows Server Update Services, more affectionately known as WSUS. For t…
Introduction At 19:33 (UST) on Tuesday 21st September the long awaited email arrived with the subject title of “ANNOUNCING THE AVAILABILITY OF WINDOWS SBS 7 PREVIEW”.  It was time to drop whatever I was doing and dedicate as much bandwidth as possi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now