Welcome to Sign in | Join | Help
in
Home Blog Forums

mapping network drives by username

Last post 04-23-2008, 3:51 PM by Killerbananas. 3 replies.

Sort Posts: Previous Next
  •  04-22-2008, 9:10 AM 1874

    mapping network drives by username

    I have several vbs scripts that I have written that work great, but I need on that will map according to username.

    Example: Username Joe would need a network drive mapped \\data\documents\joe

    in my old *.bat files all I had to do was use %username% and it would look at \\data\documents\%username% and map joe to the folder labeled joe.

     How can I do this with vbs?

     

    Thanks,
     

  •  04-23-2008, 12:27 PM 1880 in reply to 1874

    Re: mapping network drives by username

    Try this...

    'Map Home Drive
    strDriveLetter = "H:"
    strHomeServer = "\\SERVERNAME\SHARE\"
    strUserName = WSHNetwork.UserName
    WSHNetwork.MapNetworkDrive strDriveLetter, strHomeServer & strUserName


    Ryan Patel
    Sr. Network Engineer|BS|MCSE|CCNA
  •  04-23-2008, 12:55 PM 1881 in reply to 1880

    Re: mapping network drives by username

    deleted message, this posting form sucks, where's the "" tags? More than what you asked, but it's a pretty useful script. Apply security to drives, if the user has rights it will map it, if they don't it won't. Just fill in the paths between the quotes and you're ready to rock and roll.

    -----------------------------------------------

    MapDrives

    Sub MapDrives

     Dim  objNetwork, strUserName
     Dim strFDrivePath, strGDrivePath, strHDrivePath, strIDrivePath,_
      strJDrivePath, strKDrivePath, strLDrivePath, strMDrivePath,_
      strNDrivePath, strODrivePath, strPDrivePath, strQDrivePath,_
      strRDrivePath, strSDrivePath, strTDrivePath, strUDrivePath,_
      strVDrivePath, strWDrivePath, strXDrivePath, strYDrivePath,_
      strZDrivePath
     Dim FDrive, GDrive, HDrive, IDrive, JDrive, KDrive, LDrive, MDrive,_
      NDrive, ODrive, PDrive, QDrive, RDrive, SDrive, TDrive,_
      UDrive, VDrive, WDrive, XDrive, YDrive, ZDrive
     
     ON ERROR RESUME NEXT
     
     Set objNetwork = CreateObject("WScript.Network")
     strUserName = objNetwork.UserName
     
     FDrive = "F:"
     GDrive = "G:"
     HDrive = "H:"
     IDrive = "I:"
     JDrive = "J:"
     KDrive = "K:"
     LDrive = "L:"
     MDrive = "M:"
     NDrive = "N:"
     ODrive = "O:"
     PDrive = "P:"
     QDrive = "Q:"
     RDrive = "R:"
     SDrive = "S:"
     TDrive = "T:"
     UDrive = "U:"
     VDrive = "V:"
     WDrive = "W:"
     XDrive = "X:"
     YDrive = "Y:"
     ZDrive = "Z:"
     
     strFDrivePath = ""
     strGDrivePath = ""
     strHDrivePath = ""
     strIDrivePath = ""
     strJDrivePath = ""
     strKDrivePath = ""
     strLDrivePath = ""
     strMDrivePath = ""
     strNDrivePath = ""
     strODrivePath = ""
     strPDrivePath = ""
     strQDrivePath = ""
     strRDrivePath = ""
     strSDrivePath = ""
     strTDrivePath = ""
     strVDrivePath = ""
     strWDrivePath = ""
     strXDrivePath = ""
     strYDrivePath = ""
     strZDrivePath = ""
     strUDrivePath = "\\<Server Name>\" & strUserName
     
     If strFDrivePath <> "" Then
      objNetwork.MapNetworkDrive FDrive, strFDrivePath
     end if
     
     If strGDrivePath <> "" Then
      objNetwork.MapNetworkDrive GDrive, strGDrivePath
     end if

     If strHDrivePath <> "" Then
      objNetwork.MapNetworkDrive HDrive, strHDrivePath
     end if

     If strIDrivePath <> "" Then
      objNetwork.MapNetworkDrive IDrive, strIDrivePath
     end if

     If strJDrivePath <> "" Then
      objNetwork.MapNetworkDrive JDrive, strJDrivePath
     end if

     If strKDrivePath <> "" Then
      objNetwork.MapNetworkDrive KDrive, strKDrivePath
     end if

     If strLDrivePath <> "" Then
      objNetwork.MapNetworkDrive LDrive, strLDrivePath
     end if

     If strMDrivePath <> "" Then
      objNetwork.MapNetworkDrive MDrive, strMDrivePath
     end if

     If strNDrivePath <> "" Then
      objNetwork.MapNetworkDrive NDrive, strNDrivePath
     end if

     If strODrivePath <> "" Then
      objNetwork.MapNetworkDrive ODrive, strODrivePath
     end if

     If strPDrivePath <> "" Then
      objNetwork.MapNetworkDrive PDrive, strPDrivePath
     end if

     If strQDrivePath <> "" Then
      objNetwork.MapNetworkDrive QDrive, strQDrivePath
     end if

     If strRDrivePath <> "" Then
      objNetwork.MapNetworkDrive RDrive, strRDrivePath
     end if

     If strSDrivePath <> "" Then
      objNetwork.MapNetworkDrive SDrive, strSDrivePath
     end if

     If strTDrivePath <> "" Then
      objNetwork.MapNetworkDrive TDrive, strTDrivePath
     end if

     If strVDrivePath <> "" Then
      objNetwork.MapNetworkDrive VDrive, strVDrivePath
     end if

     If strWDrivePath <> "" Then
      objNetwork.MapNetworkDrive WDrive, strWDrivePath
     end if

     If strXDrivePath <> "" Then
      objNetwork.MapNetworkDrive XDrive, strXDrivePath
     end if

     If strYDrivePath <> "" Then
      objNetwork.MapNetworkDrive YDrive, strYDrivePath
     end if

     If strZDrivePath <> "" Then
      objNetwork.MapNetworkDrive ZDrive, strZDrivePath
     end if
     
     If strUDrivePath <> "" Then
      objNetwork.MapNetworkDrive UDrive, strUDrivePath
     end if
    End Sub

  •  04-23-2008, 3:51 PM 1885 in reply to 1881

    Re: mapping network drives by username

    weenis:

    deleted message, this posting form sucks, where's the "" tags?

    I believe the code tages work just fine - or am I wrong ?

     

    </P> <P>&nbsp;strUDrivePath = "<A>\&lt;Server</A> Name&gt;" &amp; strUserName
    &nbsp;
    &nbsp;If strFDrivePath &lt;&gt; "" Then
    &nbsp; objNetwork.MapNetworkDrive FDrive, strFDrivePath
    &nbsp;end if
    </P> <P>

     yep seems ok ? good post though, should help them out.

View as RSS news feed in XML


All postings are provided "AS IS" with no warranties, and confer no rights.
Microsoft product screen shot(s) reprinted with permission from Microsoft Corporation.