• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6636
  • Last Modified:

VBScript to Map network drive

Hi all,

Can someone help me with a VBScript to map a network drive based on Domain account ,on machine ,on group of DL .
thanks a lot in advance.
0
Jyotikadian
Asked:
Jyotikadian
  • 5
  • 2
  • 2
  • +1
1 Solution
 
CSecurityCommented:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set AllDrives = WshNetwork.EnumNetworkDrives()

DriveLetter = "N:" 'must be capitalized
RemotePath = "\\dave\c"

AlreadyConnected = False
For i = 0 To AllDrives.Count - 1 Step 2
If AllDrives.Item(i) = DriveLetter Then AlreadyConnected = True
Next

If AlreadyConnected = False then
WShNetwork.MapNetworkDrive DriveLetter, RemotePath
WshShell.PopUp "Drive " & DriveLetter & " connected successfully."

Else
WShNetwork.RemoveNetworkDrive DriveLetter
WshShell.PopUp "Drive " & DriveLetter & " disconnected."
End if
0
 
CSecurityCommented:
This code adds a network drive to address of RemotePath. If the address already exists, removes that... ;)
0
 
Shiju SasidharanAssoc Project ManagerCommented:
or you can use WNetAddConnection API function

http://vb-helper.com/howto_map_network_drive.html
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
Shiju SasidharanAssoc Project ManagerCommented:
0
 
CSecurityCommented:
shijusn, they are both for VB6... Jyotikadian asks for VBscript code.
0
 
JyotikadianAuthor Commented:
Hi CSecurity,

Though your script works but it does not specify the Domain account or Domain Distribution list. Can you please help me a bit more?
0
 
CSecurityCommented:
What you want to do with domain account? You just going to map a network drive and network drive have a path.

You can specify the path in my code and then map it.
0
 
EDDYKTCommented:
may be not domain administrator has capable to see the drive

8->
0
 
EDDYKTCommented:
may be just shell with net use?
0
 
CSecurityCommented:
You can use net use command like:

net use w: \\monolith\pc_dist boviks_password /user:SCS\bovik
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now