Solved

SBS2003 - Mapping Network Drives via VBS

Posted on 2010-08-27
18
751 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
ID: 33543265
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
ID: 33543331
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
ID: 33543365
How about adding this to your vbs:

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

?

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

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

Expert Comment

by:piji
ID: 33543418
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
ID: 33543444
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
ID: 33543452
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
ID: 33543492
objNetwork.RemoveNetworkDrive "Z:" "\\server\share"
0
 

Author Comment

by:NorthstarIT
ID: 33543657
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
 
LVL 4

Expert Comment

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

Author Comment

by:NorthstarIT
ID: 33543716
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
ID: 33543785
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
ID: 33543797
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
ID: 33543886
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
ID: 33543909
Took out the remove and now I get the error local device name is already in use

0
 

Author Comment

by:NorthstarIT
ID: 33543917
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
ID: 33543992
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
ID: 33544077
Thank you both. I hope you accept why I have split the points
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The SBS 2011 release date (RTM) is supposed to be around Christmas, 2011.  This article is a compilation of my notes -- things I have learned first hand.  The items are in a rather random order, but I think this list covers most of what is new and d…
If you are a user of the discontinued Microsoft Office Accounting 2008 (MSOA) and have to move to a new computer running Windows 8, you will be unhappy to discover that it won't install.  In particular, Microsoft SQL Server 2005 Express Edition (SSE…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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