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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbs logon script help needed!!

Status
Not open for further replies.

maclp

Technical User
Aug 17, 2010
3
NL
hello,

i'm in need of help with my vbscript.

i want to use it to map a drive to the users in a curtain group in AD by implementing it in group policy.

however i'm not sure if it works correctly.

the script:
On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Select Case strGroupName
Case "testgroep"
objNetwork.MapNetworkDrive "R:", "\\TOM-TELLIE\SOFTLIB"

End Select
Next




can any of you see what's wrong with it.
thanks
 
you dont need to bind to each group that the user is a memberof, why bother? you are mapping drives based on group names, you can get the group name from the

For Each strGroup in objUser.MemberOf
Wscript.Echo strGroup

you dont need the
'Set objGroup = GetObject(strGroupPath)
'strGroupName = objGroup.CN

comment out On Error Resume Next, and put in some Wscript.Echo's at key points in your script with key data being echo's otthe screen, you will soon see where you are going wrong.

 
thanks for your reply!

so my script now looks like this:

'On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Wscript.Echo strGroup

Select Case strGroupName
Case "testgroep"
objNetwork.MapNetworkDrive "R:", "\\TOM-TELLIE\SOFTLIB"

End Select
Next



is this correct?
 
does it work? i would say no, therefore, no it is not correct.

what do you get displayed from the Wscript.Echo strGroup?
Your Select Case statement uses strGroupName. this variable is blank i would suggest, change your select case to use the strGroup.
You dont need strGroupName or strGroupPath.
Try to always use Option Explicit.
The way you are mapping the drive is fine for the first time the logonscript runs, however, it might fail the second time, because the user already has the R drive mapped? or it may fail right away as the user already has the R drive mapped, and perhaps to the wrong place.
i would not recommend doing a remove mapped drive before the mapping, as then you would be unmapping and remapping at every logon which seems pointless, however, at the moment, given your limited scripting ability it may be the simplest approach.
 
Check out my FAQ, it has all the code you need on the subject:
I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top