Link to home
Create AccountLog in
Avatar of Member_2_1334455
Member_2_1334455Flag for Canada

asked on

objNetwork.MapNetworkDrive VBScript question

I have the following script set for when users log onto the domain:
(SEE CODE SNIPPET)

Id like to know, if the computer doesn't have the appropriate user name and password saved to connect to the specified servers, how can I implement that into the script (entering the user name and password) so the drives are automatically mounted?

Thanks in advance,
On Error Resume Next
 
Dim WSHNetwork, path
 
Set objNetwork = CreateObject("WScript.Network")
 
 
objNetwork.MapNetworkDrive "X:" , "\\192.168.0.103\server"
objNetwork.MapNetworkDrive "Y:" , "\\192.168.0.103\Documentation"
objNetwork.MapNetworkDrive "S:" , "\\192.168.0.100\signature"
objNetwork.MapNetworkDrive "O:" , "\\192.168.0.100\edocs"
objNetwork.MapNetworkDrive "B:" , "\\192.168.0.100\bboard"
objNetwork.MapNetworkDrive "I:" , "\\192.168.0.100\BVImages"
 
wscript.sleep 300
 
 
'Clean Up Memory Used
set WSHNetwork = Nothing
 
'Quit the Script
wscript.quit

Open in new window

Avatar of ms-pro
ms-pro
Flag of Denmark image

try this

Dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
strLocalDrive = "L:"
strRemoteShare = "\\server\share_name"
strPer = "FALSE"
strUsr = "username"
strPas = "password"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
Avatar of Member_2_1334455

ASKER

The code doesn't seem to work...
On Error Resume Next
 
Dim WSHNetwork, path
 
Dim objNetwork
 
Set objNetwork = WScript.CreateObject("WScript.Network")
strLocalDrive = "X:"
strRemoteShare = "\\192.168.0.103\server"
strPer = "FALSE"
strUsr = "USER"
strPas = "PASS"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
 
strLocalDrive = "Y:"
strRemoteShare = "\\192.168.0.103\Documentation"
strPer = "FALSE"
strUsr = "USER"
strPas = "PASS"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
 
 
strLocalDrive = "S:"
strRemoteShare = "\\192.168.0.100\signature"
strPer = "FALSE"
strUsr = "USER"
strPas = "PASS"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
 
 
strLocalDrive = "O:"
strRemoteShare = "\\192.168.0.100\edocs"
strPer = "FALSE"
strUsr = "USER"
strPas = "PASS"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
 
 
strLocalDrive = "B:"
strRemoteShare = "\\192.168.0.100\bboard"
strPer = "FALSE"
strUsr = "USER"
strPas = "PASS"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
 
 
strLocalDrive = "I:"
strRemoteShare = "\\192.168.0.100\BVImages"
strPer = "FALSE"
strUsr = "USER"
strPas = "PASS"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
 
 
wscript.sleep 300
 
 
'Clean Up Memory Used
set WSHNetwork = Nothing
 
'Quit the Script
wscript.quit

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of exx1976
exx1976
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
exx1976:

I tried your solution, but I get a syntax error.  I'm confused as to what to put in the domain section.

My domain is "hq.mrjanitorialsupplies.com" so I tried that and I still got the syntax error.

Could you please notify me what I am doing wrong?

Thanks,

Chris
Set oNetwork = CreateObject("Wscript.Network")
oNetwork.MapNetworkDrive "I:",\\192.168.0.103\BVImages",,"hq.mrjanitorialsupplies.com\USER","PASS"

Open in new window

The domain should only be the NETBIOS name of the domain, not the FQDN.  Just use   HQ   and it should work fine.
Alright this is what I did and it seems to be working fine now.

Thank You.

On Error Resume Next
 
Dim WSHNetwork, path
 
 
Set oNetwork = CreateObject("Wscript.Network")
 
oNetwork.MapNetworkDrive "B:","\\192.168.0.100\bboard",,"hq\USER","PASS"
 
oNetwork.MapNetworkDrive "I:","\\192.168.0.100\BVImages",,"hq\USER","PASS"
 
 
oNetwork.MapNetworkDrive "Y:","\\192.168.0.103\Documentation",,"hq\USER","PASS"
 
oNetwork.MapNetworkDrive "X:","\\192.168.0.103\server",,"hq\USER","PASS"
 
wscript.sleep 300
 
 
'Clean Up Memory Used
set WSHNetwork = Nothing
 
'Quit the Script
wscript.quit

Open in new window

Good answer.  Kind of needed the full script to be written out, for us n00bs :)  But awesome.  Thank you.