Solved

VBScript to Map network drive

Posted on 2006-10-31
10
6,610 Views
Last Modified: 2011-08-18
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
Comment
Question by:Jyotikadian
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 17

Accepted Solution

by:
CSecurity earned 300 total points
Comment Utility
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
 
LVL 17

Expert Comment

by:CSecurity
Comment Utility
This code adds a network drive to address of RemotePath. If the address already exists, removes that... ;)
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
Comment Utility
or you can use WNetAddConnection API function

http://vb-helper.com/howto_map_network_drive.html
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
Comment Utility
0
 
LVL 17

Expert Comment

by:CSecurity
Comment Utility
shijusn, they are both for VB6... Jyotikadian asks for VBscript code.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:Jyotikadian
Comment Utility
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
 
LVL 17

Expert Comment

by:CSecurity
Comment Utility
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
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
may be not domain administrator has capable to see the drive

8->
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
may be just shell with net use?
0
 
LVL 17

Expert Comment

by:CSecurity
Comment Utility
You can use net use command like:

net use w: \\monolith\pc_dist boviks_password /user:SCS\bovik
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now