I need a help creating a vbs script to map network drives based on user login
name

Re: Map Drives Based on User Login Name by Ray

Ray
Thu Jul 13 13:52:41 CDT 2006

What part are you stuck on?

Ray at work

"Mahir Jamakovic" <Mahir Jamakovic@discussions.microsoft.com> wrote in
message news:AF42BC56-0DF5-4E9D-92EE-5E7C6F6DFF6A@microsoft.com...
>I need a help creating a vbs script to map network drives based on user
>login
> name



Re: Map Drives Based on User Login Name by Jim

Jim
Thu Jul 13 14:02:43 CDT 2006

LOL...


"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:eUsbG2qpGHA.3584@TK2MSFTNGP03.phx.gbl...
> What part are you stuck on?
>
> Ray at work
>
> "Mahir Jamakovic" <Mahir Jamakovic@discussions.microsoft.com> wrote in
> message news:AF42BC56-0DF5-4E9D-92EE-5E7C6F6DFF6A@microsoft.com...
>>I need a help creating a vbs script to map network drives based on user
>>login
>> name
>
>



Re: Map Drives Based on User Login Name by MahirJamakovic

MahirJamakovic
Thu Jul 13 14:51:02 CDT 2006

I'm trying to modify this script so instead mapping network drives based on
group membership to map network drive based on user login name.



*********************************************************
'VBS script, Map Drives Based on Group Membership

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 "IS Staff"
objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
objNetwork.MapNetworkDrive "W:", "\\Server2\Internal"

Case "Network Staff"
objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"

Case "Domain Admins"
objNetwork.MapNetworkDrive "Y:", "\\DFS_Root\Shared"

Case "PSR Users"
objNetwork.MapNetworkDrive "Z:", "\\DFS_Root\Irwindale"
End Select
Next
************************************************************

any idea


"Ray Costanzo [MVP]" wrote:

> What part are you stuck on?
>
> Ray at work
>
> "Mahir Jamakovic" <Mahir Jamakovic@discussions.microsoft.com> wrote in
> message news:AF42BC56-0DF5-4E9D-92EE-5E7C6F6DFF6A@microsoft.com...
> >I need a help creating a vbs script to map network drives based on user
> >login
> > name
>
>
>

Re: Map Drives Based on User Login Name by Richard

Richard
Thu Jul 13 15:01:07 CDT 2006

Mahir Jamakovic wrote:

> I'm trying to modify this script so instead mapping network drives based
> on
> group membership to map network drive based on user login name.
>
> *********************************************************
> 'VBS script, Map Drives Based on Group Membership
>
> 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 "IS Staff"
> objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
> objNetwork.MapNetworkDrive "W:", "\\Server2\Internal"
>
> Case "Network Staff"
> objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
>
> Case "Domain Admins"
> objNetwork.MapNetworkDrive "Y:", "\\DFS_Root\Shared"
>
> Case "PSR Users"
> objNetwork.MapNetworkDrive "Z:", "\\DFS_Root\Irwindale"
> End Select
> Next
> ************************************************************

If you want the Distinguished Name of the user, you can use
objSysInfo.UserName, and create a "Select Case" with that. It might make
more sense to retrieve the NT Name (the "pre-Windows 2000 logon name") from
the wshNetwork object. For example:

Set objNetwork = CreateObject("Wscript.Network")
strName = objNetwork.UserName
Select Case LCase(strName)
Case "jimsmith"
objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
Case "lwilson"
objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
End Select

I made the comparisons case insensitive with the LCase function, and used
all lower case logon names. This would only be feasible with a small group
of users.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: Map Drives Based on User Login Name by MahirJamakovic

MahirJamakovic
Thu Jul 13 15:42:01 CDT 2006

I will try that now, let you know


thank you so much

"Richard Mueller" wrote:

> Mahir Jamakovic wrote:
>
> > I'm trying to modify this script so instead mapping network drives based
> > on
> > group membership to map network drive based on user login name.
> >
> > *********************************************************
> > 'VBS script, Map Drives Based on Group Membership
> >
> > 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 "IS Staff"
> > objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
> > objNetwork.MapNetworkDrive "W:", "\\Server2\Internal"
> >
> > Case "Network Staff"
> > objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
> >
> > Case "Domain Admins"
> > objNetwork.MapNetworkDrive "Y:", "\\DFS_Root\Shared"
> >
> > Case "PSR Users"
> > objNetwork.MapNetworkDrive "Z:", "\\DFS_Root\Irwindale"
> > End Select
> > Next
> > ************************************************************
>
> If you want the Distinguished Name of the user, you can use
> objSysInfo.UserName, and create a "Select Case" with that. It might make
> more sense to retrieve the NT Name (the "pre-Windows 2000 logon name") from
> the wshNetwork object. For example:
>
> Set objNetwork = CreateObject("Wscript.Network")
> strName = objNetwork.UserName
> Select Case LCase(strName)
> Case "jimsmith"
> objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
> Case "lwilson"
> objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
> End Select
>
> I made the comparisons case insensitive with the LCase function, and used
> all lower case logon names. This would only be feasible with a small group
> of users.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
>
>

Re: Map Drives Based on User Login Name by MahirJamakovic

MahirJamakovic
Thu Jul 13 16:38:01 CDT 2006

Thank you very much this will work for me

"Richard Mueller" wrote:

> Mahir Jamakovic wrote:
>
> > I'm trying to modify this script so instead mapping network drives based
> > on
> > group membership to map network drive based on user login name.
> >
> > *********************************************************
> > 'VBS script, Map Drives Based on Group Membership
> >
> > 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 "IS Staff"
> > objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
> > objNetwork.MapNetworkDrive "W:", "\\Server2\Internal"
> >
> > Case "Network Staff"
> > objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
> >
> > Case "Domain Admins"
> > objNetwork.MapNetworkDrive "Y:", "\\DFS_Root\Shared"
> >
> > Case "PSR Users"
> > objNetwork.MapNetworkDrive "Z:", "\\DFS_Root\Irwindale"
> > End Select
> > Next
> > ************************************************************
>
> If you want the Distinguished Name of the user, you can use
> objSysInfo.UserName, and create a "Select Case" with that. It might make
> more sense to retrieve the NT Name (the "pre-Windows 2000 logon name") from
> the wshNetwork object. For example:
>
> Set objNetwork = CreateObject("Wscript.Network")
> strName = objNetwork.UserName
> Select Case LCase(strName)
> Case "jimsmith"
> objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
> Case "lwilson"
> objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
> End Select
>
> I made the comparisons case insensitive with the LCase function, and used
> all lower case logon names. This would only be feasible with a small group
> of users.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
>
>

Re: Map Drives Based on User Login Name by D

D
Thu Jul 13 16:50:09 CDT 2006

Mahir,

You have to be careful with ".MemberOf" - I mean, if a user is a member of
only one group then ".MemberOf" is actually a "string" datatype. It is only
a "collection" datatype if the user is a member of two or more groups, and
it is "empty" if there are no groups. The code below illustrates what I
mean, and you'll have to tweak it to suit your needs.

Regards,
Dave.




Sub s_load_groups_ad( po_ad_object )
Const cs_fac = "%s_load_groups_ad, "
Dim lc_ls_groups, lo_group, ll_j

lc_ls_groups = po_ad_object.MemberOf 'Could be a collection, could be a
string.

If IsEmpty( lc_ls_groups ) Then Exit Sub

If TypeName( lc_ls_groups ) = "String" Then
set lo_group = GetObject( "LDAP://" & lc_ls_groups )
If Not gd_groups.Exists( lo_group.sAMAccountName ) Then
gd_groups( lo_group.sAMAccountName ) = "LDAP://"
Call s_load_groups_ad( lo_group )
End If
Set lo_group = Nothing
Exit Sub
End If

For ll_j = 0 To UBound( lc_ls_groups )
Set lo_group = GetObject( "LDAP://" & lc_ls_groups(ll_j) )
If Not gd_groups.Exists( lo_group.sAMAccountName ) Then
gd_groups( lo_group.sAMAccountName ) = "LDAP://"
Call s_load_groups_ad( lo_group )
End If
Next
Set lo_group = Nothing
End Sub





"Mahir Jamakovic" <MahirJamakovic@discussions.microsoft.com> wrote in
message news:7159D753-F967-4C41-8CFC-5AC361BF08A6@microsoft.com...
> Thank you very much this will work for me
>
> "Richard Mueller" wrote:
>
>> Mahir Jamakovic wrote:
>>
>> > I'm trying to modify this script so instead mapping network drives
>> > based
>> > on
>> > group membership to map network drive based on user login name.
>> >
>> > *********************************************************
>> > 'VBS script, Map Drives Based on Group Membership
>> >
>> > 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 "IS Staff"
>> > objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
>> > objNetwork.MapNetworkDrive "W:", "\\Server2\Internal"
>> >
>> > Case "Network Staff"
>> > objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
>> >
>> > Case "Domain Admins"
>> > objNetwork.MapNetworkDrive "Y:", "\\DFS_Root\Shared"
>> >
>> > Case "PSR Users"
>> > objNetwork.MapNetworkDrive "Z:", "\\DFS_Root\Irwindale"
>> > End Select
>> > Next
>> > ************************************************************
>>
>> If you want the Distinguished Name of the user, you can use
>> objSysInfo.UserName, and create a "Select Case" with that. It might make
>> more sense to retrieve the NT Name (the "pre-Windows 2000 logon name")
>> from
>> the wshNetwork object. For example:
>>
>> Set objNetwork = CreateObject("Wscript.Network")
>> strName = objNetwork.UserName
>> Select Case LCase(strName)
>> Case "jimsmith"
>> objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
>> Case "lwilson"
>> objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
>> End Select
>>
>> I made the comparisons case insensitive with the LCase function, and used
>> all lower case logon names. This would only be feasible with a small
>> group
>> of users.
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>>
>>
>>