No announcement yet.

map an arbitrary drive, with arbitrary credentials.

  • Filter
  • Time
  • Show
Clear All
new posts

  • map an arbitrary drive, with arbitrary credentials.

    Ok, So what I have is an environment where users collaborate with shared data from their home directories; which are hidden shares on our server; i.e., \\server\user$

    I want to map a random drive letter (which i can get from an input box), delete the share, if existing, and remap to the new share point,

    I understand how to get a username via an inputbox(), and concatenate to get the hidden share.

    How can I prompt the user for a password, in a "pretty way", and mask it from prying eyes?

    Option Explicit
    Dim objShell, objNetwork
    Dim DriveLetter1, DriveLetter2, RemotePath1, RemotePath2
    Dim AllDrives, AlreadyConnected, Network1, Network2, i
    Dim strUser, strRemotePath

    Set Network1 = CreateObject("WScript.Network")

    DriveLetter1 = "M:"

    strUser = inputBox("User Name:")
    strUser = StrUser & "$"
    strRemotePath = "\\server\"
    RemotePath1 = strRemotePath & strUser

    WScript.Echo "Pathname: "& RemotePath1

    Set objShell = CreateObject("WScript.Shell")
    Set objNetwork = CreateObject("WScript.Network")
    Set AllDrives = objNetwork.EnumNetworkDrives()

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

    If AlreadyConnected = True then
    objNetwork.RemoveNetworkDrive DriveLetter1
    objShell.PopUp "Drive " & DriveLetter1 & " disconnected."
    objNetwork.MapNetworkDrive DriveLetter1, RemotePath1
    objShell.PopUp "Drive " & DriveLetter1 & " connected successfully."
    End if

    Last edited by morrisonmorgan; 29th June 2008, 19:51. Reason: finger slipped and i hit enter too early!~