Jump to content

Recommended Posts


Posted

I have been using a windows scripting host script and it seems to work. Here is the code I have been using for this:

paste this into notepad and rename it to map.vbs or whatever you want. It should do the trick.

For my needs I have it clearing all network connections each time it runs and mapping one drive to Z

it works for what I need.

'Map a network drive of your choice

'Created by John Hlaj

'Jan 28, 2007

Option Explicit

Dim objNetwork

Dim i, clDrives, WSHNetwork, strDriveLetter, strRemotePath ,strUserName, strPassword , strProfile

'Disconnect ALL mapped drives

Set WSHNetwork = CreateObject("WScript.Network")

Set clDrives = WshNetwork.EnumNetworkDrives

For i = 0 to clDrives.Count -1 Step 2

WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True

Next

'Give the PC time to do the disconnect, wait 300 milliseconds

wscript.sleep 300

'Set drive to Z and request remote path

strDriveLetter = "Z:"

strRemotePath = InputBox("Enter remote path eg. \\server\share", "Map Network Drive by John Hlaj")

if IsEmpty(strRemotePath) then

Wscript.Quit

end if

strUserName = InputBox("Enter user name.", "Map Network Drive by John Hlaj")

if IsEmpty(strUserName) then

Wscript.Quit

end if

strPassword = InputBox("Enter password.", "Map Network Drive by John Hlaj")

if IsEmpty(strPassword) then

Wscript.Quit

end if

strProfile = "false"

' Creates a network object

' Then to apply the MapNetworkDrive method.

Set objNetwork = CreateObject("WScript.Network")

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath , strProfile, strUserName, strPassword

' Extra code just to add a message box

WScript.Echo strRemotePath & " mapped to: " & strDriveLetter

WScript.Quit

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...