Announcement

Collapse
No announcement yet.

Scripting Mapping Network drive in VB and keeping the map for next logon?

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

  • Scripting Mapping Network drive in VB and keeping the map for next logon?

    Hello All,

    I am hoping that someone will have a solution to my problem.

    I have written a script in VB to map my network drives and would like to keep them for every logon not just once but i can not seem to get the script to work.
    Option Explicit
    Dim objNetwork
    Dim strRemotePath1, strRemotePath2, strRemotePath3, strRemotePath4, strRemotePath5
    Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, strDriveLetter4, strDriveLetter5
    Dim strUserName

    strDriveLetter1 = "Q:"
    strDriveLetter2 = "S:"
    strDriveLetter3 = "T:"
    strDriveLetter4 = "U:"
    strDriveLetter5 = "V:"
    strRemotePath1 = "\\Mainserver\Q Drive"
    strRemotePath2 = "\\Mainserver\S Drive"
    strRemotePath3 = "\\Mainserver\T Drive"
    strRemotePath4 = "\\Mainserver\U Drive"
    strRemotePath5 = "\\Mainserver\V Drive"


    Set objNetwork = CreateObject("WScript.Network")

    ' Section which maps the drives,
    objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
    objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
    objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
    objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4
    objNetwork.MapNetworkDrive strDriveLetter5, strRemotePath5



    ' Extra code just to add a message box
    WScript.Echo "Map drives " & strDriveLetter1 & " & " & strDriveLetter2 & " & " & strDriveLetter3 & " & " & strDriveLetter4 & " & " & strDriveLetter5

    Wscript.Quit

  • #2
    Re: Scripting Mapping Network drive in VB and keeping the map for next logon?

    To store the mapping persistently in the users profile - use the third parameter (type: TRUE):
    Code:
    '---------<snip>
    objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1, TRUE
    objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2, TRUE
    objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3, TRUE
    objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4, TRUE
    objNetwork.MapNetworkDrive strDriveLetter5, strRemotePath5, TRUE
    '---------<snip>
    Syntax

    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, [persistent], [strUser], [strPassword])


    Options:

    strDriveLetter : The local drive letter (e.g. L:)

    strRemotePath : The UNC path to the share (String value)

    'persistent' : True/False - store the mapping persistently in the users profile (default = FALSE)

    'strUser' : The user name. (Optional)

    'strPassword' : The password. (Optional)


    source: http://www.ss64.com/wsh/drivemap.html


    \Rems

    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: Scripting Mapping Network drive in VB and keeping the map for next logon?

      Thanks for the quick reply.

      Comment

      Working...
      X