1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mapping user drive

Discussion in 'Scripting & Programming' started by michael78, Apr 11, 2005.

  1. michael78

    michael78 Terabyte Poster

    2,085
    29
    141
    Hi all I have a major problem with my VBS logon script. All of it works apart from mapping a user drive. At work each person has a folder to store their work in this is mapped as a U drive. In the past when people logged on it mapped their U drive and username name so that they couldn't access anyone elses personal folder now I can only get it to map to the U drive but they can go into anyone elses folder in the U drive. My code to do this is:

    MapDrive "u:", "\\nclestore\home" & UserName

    am I doing something wrong?

    Cheers in Advance

    Michael
     
    Certifications: A+ | Network+ | Security+ | MCP | MCDST | MCTS: Hyper-V | MCTS: AD | MCTS: Exchange 2007 | MCTS: Windows 7 | MCSA: 2003 | ITIL Foundation v3 | CCA: Xenapp 5.0 | MCITP: Enterprise Desktop Administrator on Windows 7 | MCITP: Enterprise Desktop Support Technician on Windows 7
    WIP: Online SAN Overview, VCP in December 2011
  2. Phoenix
    Honorary Member

    Phoenix 53656e696f7220 4d6f64

    5,726
    175
    221
    so are you saying its only mapping to the root of xxx\home
    or is it just case of users being able to click the 'parent directory' button and stuff?
     
    Certifications: MCSE, MCITP, VCP
    WIP: > 0
  3. michael78

    michael78 Terabyte Poster

    2,085
    29
    141
    Phoenix basically when each user clicks into their U drive they should only be able to access their own folder. I've posted my entire script below if this helps. I just can't get it to map the the U drive. I've highlighted the mapping I'm having problems with in Red. Go easy on me I've never used VBS before...:D



    '**********************************************************************************
    ' Set Environment Variables
    '*********************************************************************************
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    Set WSHShell = WScript.CreateObject("WScript.Shell")
    On Error Resume Next
    Domain = WSHNetwork.UserDomain
    UserName = ""
    While UserName = ""
    UserName = WSHNetwork.UserName
    MyGroups = GetGroups(Domain, UserName)
    Wend
    '*********************************************************************************
    ' Main Process:
    '*********************************************************************************
    GrpMeb UserName
    ShowBox
    Wscript.Quit
    '*********************************************************************************
    'Function: GetGroups
    '*********************************************************************************
    Function GetGroups(Domain, UserName)
    Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
    GetGroups=""
    For Each objGroup In objUser.Groups
    GetGroups=GetGroups & "[" & UCase(objGroup.Name) & "]"
    Next
    End Function
    '********************************************************************************
    'Function: InGroup
    '********************************************************************************
    Function InGroup(strGroup)
    InGroup=False
    If InStr(MyGroups,"[" & UCase(strGroup) & "]") Then
    InGroup=True
    End If
    End Function
    '*********************************************************************************
    ' MapDrives Subroutine
    '*********************************************************************************
    Sub MapDrive(sDrive,sShare)
    On Error Resume Next
    WSHNetwork.RemoveNetworkDrive sDrive
    Err.Clear
    WSHNetwork.MapNetworkDrive sDrive,sShare
    End Sub
    '********************************************************************************
    'Map Drives:
    '********************************************************************************
    Sub GrpMeb(UNAME)
    MapDrive "h:", "
    \\ncleaccounts\jobcost$"
    MapDrive "i:", "
    \\nclecad\cad$"
    MapDrive "j:", "
    \\10.17.1.10\bsapps$"
    MapDrive "o:", "
    \\nclestore\officedat"
    MapDrive "p:", "
    \\ncleaccounts\accdata$"
    MapDrive "r:", "
    \\ncleripac\qsapps"
    MapDrive "u:", "\\nclestore\Data\home" & strUserName
    WSHNetwork.AddWindowsPrinterConnection "\\ncleprint\PrintB&W"
    WSHNetwork.AddWindowsPrinterConnection "
    \\ncleprint\Postb&w"
    WSHNetwork.AddWindowsPrinterConnection "
    \\ncleprint\PrintRoom_Colour"
    WSHNetwork.AddWindowsPrinterConnection "
    \\hp-plotter\plotter"
    Return = WSHShell.Run("
    \\ncletrend\OFCSCAN\AUTOPCC.exe", 5, true)
    End Sub
    '
    '********************************************************************************
    'Display Dialog:
    '********************************************************************************
    Sub ShowBox
    strMsgtxt = "You are mapped to the following drive letters:" & vbNewLine
    strMsgtxt = strMsgtxt & "h: =
    \\ncleaccounts\jobcost$" & vbNewLine
    strMsgtxt = strMsgtxt & "i: =
    \\nclecad\cad$" & vbNewLine
    strMsgtxt = strMsgtxt & "j: =
    \\10.17.1.10\bsapps$" & vbNewLine
    strMsgtxt = strMsgtxt & "o: =
    \\nclestore\officedat" & vbNewLine
    strMsgtxt = strMsgtxt & "p: =
    \\ncleaccounts\accdata$" & vbNewLine
    strMsgtxt = strMsgtxt & "r: =
    \\ncleripac\qsapps" & vbNewLine
    strMsgtxt = strMsgtxt & "u: =
    \\nclestore\home\" & vbNewLine
    strMsgtxt = strMsgtxt & "You are mapped to the following printers:" & vbNewLine
    strMsgtxt = strMsgtxt & "
    \\ncleprint\PrintB&W as Default Printer" & vbNewLine
    strMsgtxt = strMsgtxt & "
    \\ncleprint\Postb&w" & vbNewLine
    strMsgtxt = strMsgtxt & "
    \\ncleprint\PrintRoom_Colour" & vbNewLine
    strMsgtxt = strMsgtxt & "
    \\hp-plotter\plotter" & vbNewLine
    msgbox = WshShell.Popup(strMsgtxt, 2, "Logon Script", 0)
    End Sub
     
    Certifications: A+ | Network+ | Security+ | MCP | MCDST | MCTS: Hyper-V | MCTS: AD | MCTS: Exchange 2007 | MCTS: Windows 7 | MCSA: 2003 | ITIL Foundation v3 | CCA: Xenapp 5.0 | MCITP: Enterprise Desktop Administrator on Windows 7 | MCITP: Enterprise Desktop Support Technician on Windows 7
    WIP: Online SAN Overview, VCP in December 2011
  4. Phil
    Honorary Member

    Phil Gigabyte Poster

    1,680
    7
    87
    try changing

    MapDrive "u:", "\\nclestore\Data\home" & strUserName

    to

    MapDrive "u:", "\\nclestore\Data\home\" & UserName

    You missed off \ at the end of home and the username was placed in a variable called UserName earlier in the script, not StrUserName.

    As it stands, the script will just map a drive to the home directory instead of the users subdirectory in home because StrUserName doesn't contain anything. Removing the Str part will provide the username to the mapdrive command. If you added

    option explicit to the start of the script it would have generated an error when it came across the undefined variable. If you do that you will have to Dim all the variables in the script though.

    Let us know how you get on :)
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade
  5. michael78

    michael78 Terabyte Poster

    2,085
    29
    141
    Cheers Phil worked a charm your a life saver...:D
     
    Certifications: A+ | Network+ | Security+ | MCP | MCDST | MCTS: Hyper-V | MCTS: AD | MCTS: Exchange 2007 | MCTS: Windows 7 | MCSA: 2003 | ITIL Foundation v3 | CCA: Xenapp 5.0 | MCITP: Enterprise Desktop Administrator on Windows 7 | MCITP: Enterprise Desktop Support Technician on Windows 7
    WIP: Online SAN Overview, VCP in December 2011
  6. Phil
    Honorary Member

    Phil Gigabyte Poster

    1,680
    7
    87
    Good Stuff :thumbleft
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade

Share This Page

Loading...