+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, Map folder depending upon group membership in workgroup in Coding and Web Development; This is easy in a domain, but my scenario is a workgroup of XP Pro PCs. One is designated as ...
  1. #1

    Join Date
    May 2009
    Location
    UK
    Posts
    291
    Thank Post
    64
    Thanked 21 Times in 20 Posts
    Rep Power
    14

    Map folder depending upon group membership in workgroup

    This is easy in a domain, but my scenario is a workgroup of XP Pro PCs. One is designated as a File Server and I need to be able to map to a particular folder, depending upon the group to which the user belongs. I have a startup script in the C:\...\All Users\Start Menu\Programs\Startup of each PC and would like to add to it. I know I can have:

    Code:
    net use * /delete
    net use f: \\server\AdminShare
    or
    Code:
    net use * /delete
    net use g: \\server\OtherShare
    etc. in each specific users' Startup folder but I'd like to have it run from the All Users' Startup folder so I don't have to put the login script into the specific folder when I create new users and allocate them to groups.

    Is there any way to do this? I thought of this pseudocode:
    Code:
    net use * /delete
    if group = "Administrators" then
         net use f: \\server\AdminShare
    goto end
    if group = "Power Users" then
        net use f: \\server\OtherShare
    goto end
    Maybe someone can suggest a simpler solution for me? I know that the syntax that I've given isn't VBS but I'd hope to incorporate any suggestions into my VBS login script.

    Thanks in advance.

  2. #2

    Michael's Avatar
    Join Date
    Dec 2005
    Location
    Birmingham
    Posts
    8,941
    Thank Post
    232
    Thanked 1,510 Times in 1,206 Posts
    Rep Power
    328
    There isn't really any simple solution to this. You could map both drives in a single logon script, but then configure permissions so users can access either one or the other (depending who they logon as).

  3. #3

    Join Date
    May 2009
    Location
    UK
    Posts
    291
    Thank Post
    64
    Thanked 21 Times in 20 Posts
    Rep Power
    14
    Thanks Michael. I've configured the share and folder permissions appropriately. I'd prefer to hide folders to which users don't have access, hence the idea of deleting all the mapped folders and recreating the mapping at each login.

    Since posting earlier today, I've investigated further:

    Code:
    net localgroup > group.txt
    will get me a list of local groups. I can run through them:

    Code:
    net localgroup <groupname> | find "Name" (I need to check the syntax of passing %username% to this line)
    but I'll need to save the groupname to a variable if "Name" is found in this group.

    I *think* I'm on the right track but realise that it's not so easy as it would be if it were a domain.

  4. #4

    Michael's Avatar
    Join Date
    Dec 2005
    Location
    Birmingham
    Posts
    8,941
    Thank Post
    232
    Thanked 1,510 Times in 1,206 Posts
    Rep Power
    328
    This article may point you in the right direction.

  5. Thanks to Michael from:

    Ignatius (20th June 2009)

  6. #5

    Join Date
    May 2009
    Location
    UK
    Posts
    291
    Thank Post
    64
    Thanked 21 Times in 20 Posts
    Rep Power
    14
    Thanks again. I'd had a look at that site and suspect that the code relates to a domain rather than a workgroup. When it mentions "groups", I think it refers to AD groups.

    I'll be able to test this out early next week on the workgroup and I'll also have access to a Windows 2003 and single XP Pro client to check out whether it's only for a domain.

  7. #6

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    You should be able to use the code below. Basically, it gets the name of the user and computer, clears all existing drive mappings and then connects to the user object to get its properties. It then loops through all the groups, converts the name to lower case (may not be necessary but does no harm ...) and then calls a routine to check what drives should be mapped for the groups.

    You'll need to change the "mapdrive" subroutine to deal with the groups you have and the shares you want to use.

    the only thing this won't cope with is nested groups but I'm guessing that in a workgroup you're not likely to have such a problem.

    Code:
    Set oNetwork = CreateObject("Wscript.Network")
    sUser=oNetwork.UserName
    sComputer=oNetwork.computername
    
    ClearMappedDrives
    
    set oUser=getobject("WinNT://" & sComputer & "/" & sUser)
    
    
    for each oGroup in oUser.groups
      sGroup=lcase(oGroup.name)
      MapDrive sGroup
    next
    
    
    sub clearmappeddrives
      set oDrives=oNetwork.enumnetworkdrives
      For i = 0 to oDrives.Count - 1 Step 2
        onetwork.removenetworkdrive oDrives.Item(i)
      Next
    end sub
    
    sub MapDrive(sGroup)
      select case sGroup
        case "administrators"
          oNetwork.mapnetworkdrive "z:","\\computer1\share1"
          oNetwork.mapnetworkdrive "q:","\\computer2\sharedocs"
        case "finance"
         oNetwork.mapnetworkdrive "q:","\\computer2\sharedocs"
        case "registry"
         oNetwork.mapnetworkdrive "q:","\\computer2\sharedocs"
      end select
    end sub

  8. Thanks to srochford from:

    Ignatius (21st June 2009)

  9. #7

    Join Date
    May 2009
    Location
    UK
    Posts
    291
    Thank Post
    64
    Thanked 21 Times in 20 Posts
    Rep Power
    14
    Thanks Steve - that looks good. I'll be able to test it within the next few days.

SHARE:
+ Post New Thread

Similar Threads

  1. [ASP.net] Show webpage based on group membership
    By MK-2 in forum Web Development
    Replies: 1
    Last Post: 9th April 2009, 11:53 AM
  2. Group Policy loopback affecting folder redirection
    By rocknrollstar in forum Windows
    Replies: 2
    Last Post: 25th November 2008, 07:05 AM
  3. Replies: 2
    Last Post: 1st August 2007, 10:59 AM
  4. Group Policy folder lockdown
    By speckytecky in forum General Chat
    Replies: 2
    Last Post: 12th July 2007, 08:29 AM
  5. Group Membership Woes (Need Help)
    By ICTNUT in forum Windows
    Replies: 11
    Last Post: 2nd December 2005, 03:19 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •