Announcement

Collapse
No announcement yet.

VBscript - maps a drive to any available letter

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBscript - maps a drive to any available letter

    hey guys

    "long time reader, first time poster".

    What I want is a script that maps a drive to any available letter

    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.MapNetworkDrive "find available letter:", "\\servername\folder"

    I have seached for this answer but have had no luck. i through this would be a easy one.


    Thanks
    Stevross
    "Have a good one"

  • #2
    Re: VBscript - maps a drive to any available letter

    Hi Stevross,

    The function below can do that.

    Code:
    strUNC = "\\server\share" 
    
    Set objNetwork = CreateObject("WScript.Network") 
    objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC
    
    
    '-------------------------------------------------
    Function AvailableDriveLetter
       With CreateObject("Scripting.FileSystemObject")
          For i = Asc("D") To Asc("Z") 
             If Not .DriveExists(Chr(i)) Then 
                AvailableDriveLetter = Chr(i) & ":" 
                Exit For 
             End If 
          Next
       End With
    End Function

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: VBscript - maps a drive to any available letter

      Thanks Rems that work great.

      Thanks
      Stevross
      "Have a good one"

      Comment


      • #4
        Re: VBscript - maps a drive to any available letter

        Brilliant, I was just pondering on this.

        Can you use this same one to call up three different letters?

        i.e.

        Code:
        objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC1
        objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC2
        objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC3
        This is my signature.

        Comment


        • #5
          Re: VBscript - maps a drive to any available letter

          Originally posted by Lan View Post
          Brilliant, I was just pondering on this.

          Can you use this same one to call up three different letters?

          i.e.

          Code:
          objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC1
          objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC2
          objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC3
          This should work. Make sure you have the function and values assigned to strUNCx.
          Andrew

          ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

          Comment

          Working...
          X