Link to home
Start Free TrialLog in
Avatar of NorthstarIT
NorthstarITFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SBS2003 - Mapping Network Drives via VBS

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
Avatar of acstechee
acstechee
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of NorthstarIT

ASKER

I too would use a batch file however this needs to work with the printer mapping too which is in VBS
How about adding this to your vbs:

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

?

Can I multiply the above code x 4, one for each drive?
Just add this command

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

Net use command is used for bath file.
SOLUTION
Avatar of piji
piji
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What would be the command to delete a network drive before using the objNetwork.mapnetworkdrive "z:", "\\server\share"
?
objNetwork.RemoveNetworkDrive "Z:" "\\server\share"
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?
you might need a comma in between the drive letter and location. Sorry, my bad.
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
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
You get error message because if there is no "K:", it couldn't remove. it. Why you need to remove the drive?
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
Took out the remove and now I get the error local device name is already in use

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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you both. I hope you accept why I have split the points