Jump to content

Map folder depending upon group membership in workgroup


Recommended Posts

Posted

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:

 

net use * /delete
net use f: \\server\AdminShare

or

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:

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.

Posted
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).
Posted

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:

 

net localgroup > group.txt

 

will get me a list of local groups. I can run through them:

 

net localgroup  | 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.

Posted

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.

Posted

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.

 

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

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...