Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map to Drive

Status
Not open for further replies.

sshafe

Programmer
Oct 18, 2002
71
US
Anyone know how to map to a drive through VBSCRIPT?


Thanks in advance :)
 
sshafe,

Assuming your NT or >, this works for me.

net use m: \\3.91.111.236\C$ password /user:username

More on net use, check out MS Help from Start and try typing in "net"

Hope this helps.
DougCranston
 
Here's a VBS script that works for me. Good luck.


dim OlyNet
dim OlyPrinter
dim OlyFSO
dim OlyShell
dim OlyDrives
dim i
dim cmd

on error resume next

set OlyNet = WScript.CreateObject("WScript.Network")
set OlyPrinters = WScript.CreateObject("WScript.Shell")
Set OlyFSO = WScript.CreateObject("Scripting.FileSystemObject")
set OlyShell = CreateObject("WScript.Shell")
set OlyDrives = OlyNet.EnumNetworkDrives

'----- Set Drive Mappings (This clears any existing mappings)

DriveMapping "G:", ""
DriveMapping "H:", ""
DriveMapping "I:", ""
DriveMapping "J:", ""
DriveMapping "K:", ""
DriveMapping "L:", ""
DriveMapping "M:", ""
DriveMapping "N:", ""
DriveMapping "O:", ""
DriveMapping "P:", ""
DriveMapping "Q:", ""
DriveMapping "R:", ""
DriveMapping "S:", ""
DriveMapping "T:", ""
DriveMapping "U:", ""
DriveMapping "V:", ""
DriveMapping "W:", ""
DriveMapping "X:", ""
DriveMapping "Y:", ""
DriveMapping "Z:", ""

DriveMapping "G:", "\\servername\share"


Sub DriveMapping(Drive, Share)
For i = 0 to OlyDrives.Count -1 Step 2
if LCase(Drive) = LCase(OlyDrives.Item(i)) then
if not LCase(Share) = LCase(OlyDrives.Item(i+1)) then
OlyNet.RemoveNetworkDrive Drive, true, true
Else
Exit Sub
End if
End if
Next
OlyNet.MapNetworkDrive Drive, Share
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top