Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Markdmac - VBScript for mapping drives

Status
Not open for further replies.

rmwendwa

MIS
Mar 23, 2005
22
KE
I have edited the script below to meet my user needs. its for a small college and all students belong to a group called students for easy administration. Now these students also belong to other seperate groups apart from the students group depending on the courses they are taking e.g information technology, library studies etc. now when a user logs in he can view his home folder located on the path \\server01\students home$\%username% - drive G:, the students common folder on the path \\server01\users$\students folder - drive H:, but the drive I: which i have created for them depending on the groups there in (that is course) is not mapping. Is there an error on my script. help me out

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, Groupobj, UserObj, Path


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Map drives needed by all
WSHNetwork.MapNetworkDrive "G:", "\\server01\students home$\%username%",True
WSHNetwork.MapNetworkDrive "H:", "\\server01\users$\Students Folder",True


'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
Case "InformationTechnology"
WSHNetwork.MapNetworkDrive "I:", "\\Server01\users$\Information Technology",True
Case "BusinessStudies"
WSHNetwork.MapNetworkDrive "I:", "\\Server01\users$\Business Studies",True
Case "LibraryStudies"
WSHNetwork.MapNetworkDrive "I:", "\\Server01\users$\Library Studies",True
Case "SecretarialStudies"
WSHNetwork.MapNetworkDrive "I:", "\\Server01\users$\Secretarial Studies",True
End Select
NEXT

'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing


'Quit the Script
wscript.quit
 
Forgive me for saying so but that is a lot of code to map a drive. If you are using VB for a lot of other stuff then ignore this.

You could do this in about 5 lines of KIX.

[blue]Arguably the best cat skinner around ! [/blue]

Cheers
Scott
 
I would test your script by adding an Echo statement to show you what groups the script can see the user is a member of. Add that first above the Select Case statement. Next determine that it is matching that info by adding another Echo just above your map I commands.

Another thing you might do it force a case for the checking like this:

Select Case lcase(GroupObj.Name)
Case "informationtechnology"



I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hi rmwenda,

If you add this line : wscript.echo GroupObj.Name
right before: Select Case GroupObj.Name
you should get a popup with the groupname.
to see if it is the same as the ones in the select statement...

I tried the script with me, and the retrieal proces of the GroupObj.Name property works for me, so nothing wrong there...


Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
Damn, need to refresh my page more often... [banghead]

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
Thanks guyz for your quick response to my need. Thanks markdmac, ascotta, and Kob3. i found out my error as soon as i posted my grievances - it was stupid something to do with assigning my groups to the respevtive users i hadn't done that. The code is all working out fine. Sorry and thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top