General discussion

Locked

VB Login Script Help needed

By RhythmMethod ·
Please forgive me, but i'm extremely new to VBScript. I need to write a login script to map drives based on group membership in a windows 2003 AD Domain. I've found numerous examples all over the net, but none of them has seemed to work properly for me.

Here is one of the examples that i've been playing with:

Const ACCOUNTING_GROUP = "cn=accounting"
Const IT_GROUP = "cn=information technology"

Dim wshNetwork, objUser, CurrentUser, strGroup, fso

Set wshNetwork = CreateObject("WScript.Network")
Set fso = CreateObject ("Scripting.FileSystemObject")
Set objNetwork = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objNetwork.UserName)
strGroup = LCase(Join(objNetwork.UserName))

'ACCOUNTING
If InStr(wshNetwork.UserDomain,wshNetwork.UserName, "ACCOUNTING_GROUP") Then
wshNetwork.MapNetworkDrive "V:", "\\SERVER\ACCOUNTING_SHARE"
wshNetwork.MapNetworkDrive "Z:", "\\SERVER\ACCOUNTING_SHARE2"
wshNetwork.AddWindowsPrinterConnection "\\PrintServer\EngLaser"
wshNetwork.AddWindowsPrinterConnection "\\PrintServer\Plotter"
wshNetwork.SetDefaultPrinter "\\PrintServer\EngLaser"
End If

'INFORMATION TECHNOLOGY
If InStr(wshNetwork.UserDomain,wshNetwork.UserName, "IT_GROUP") Then
wshNetwork.MapNetworkDrive "V:", "\\SERVER\IT_SHARE"
wshNetwork.MapNetworkDrive "Z:", "\\SERVER\IT_SHARE2"
wshNetwork.AddWindowsPrinterConnection "\\PrintServer\FinLaser"
wshNetwork.SetDefaultPrinter "\\PrintServer\FinLaser"
End If

I can get it to map to the first set of drives (information technology group), but whenever i assign the script to a user in another group other than information technology (ie: accounting), it still maps to the IT shares.

Should i be using a sub for each groups drive mappings? If so, what 'if' statements would be needed, and how would they look in order to call the appropriate sub?

Hopefully i've given enough information. If i'm missing anything, let me know.

Any help would be greatly appreciated.

Thanks.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

No chance of the users being in both groups is there?

by Tony Hopkinson In reply to VB Login Script Help need ...

Chnage the accounting ones to different drive letters if they are in both you'll get four then

Collapse -

Problem Solved

by RhythmMethod In reply to No chance of the users be ...

I found a new script, but i believe i've also found the original problem. My accounting user that i was testing with was a member of my accounting users group, and the domain users group. I created another global group, added the user, and the script worked. I'm not sure (maybe it's a bug), but maybe the user needs to be a member of more than one group for the script to work - don't know why, i'm still new to this. I've created another user, and tested the script successfully.

Thanks for the suggestion.

Collapse -

Here's the final script

by RhythmMethod In reply to VB Login Script Help need ...

Here's the script i ended up settling on:

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 "Accounting"
objNetwork.MapNetworkDrive "V:", "\\SERVER\SHARE"
objNetwork.MapNetworkDrive "Z:", "\\SERVER\SHARE"
Case "HR"
objNetwork.MapNetworkDrive "V:", "\\SERVER\SHARE"
objNetwork.MapNetworkDrive "Z:", "\\SERVER\SHARE"
Case "Information Technology"
objNetwork.MapNetworkDrive "V:", "\\SERVER\SHARE"
objNetwork.MapNetworkDrive "Z:", "\\SERVER\SHARE"
objNetwork.MapNetworkDrive "W:", "\\IT-BACKEND0\SHARE"
objNetwork.MapNetworkDrive "X:", "\\SERVER\SHARE"
Case "Finance"
objNetwork.MapNetworkDrive "V:", "\\SERVER\SHARE"
objNetwork.MapNetworkDrive "Z:", "\\SERVER\SHARE"
End Select
Next

Collapse -

Well I'm glad that bouncing

by Tony Hopkinson In reply to Here's the final script

the problem off my head worked for you !
LOL

Mucho points for posting the solution.
I can usually help with coding logic but I'm seriously out of date on the windows admin front, haven't done that since 99.

Collapse -

Need the same soultion.

by nathan.keever In reply to VB Login Script Help need ...

I need the same solution but have not been able to get the solutions in this thread to work. I have tried the following but get an error on line 21 Char: 1 error: The specified domain either does not exist or could not be contacted. code:8007054B Source:(null)


Const IT = "cn=it"
Const CORPORATE = "cn=corporate"
Const SERVICES = "cn=services"
Const UNIVERSITY = "cn=university"

' ======================================================
' MAP HOME DRIVE H:
' ======================================================

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "h:", "\\pways50-fs1\Profiles\" & wshNetwork.UserName


' ======================================================
' COMPILE USER GROUP MEMBERSHIPS
' ======================================================

set ADSysInfo = CreateObject("ADSystemInfo")
set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
if IsArray(CurrentUser.MemberOf) then
strGroups = LCase(Join(CurrentUser.MemberOf))
' else
'strGroups = LCase(CurrentUser.MemberOf)
end if
'set ADSysInfo = nothing
'set CurrentUser = nothing

' ======================================================
' MAP DRIVES
' ======================================================
If InStr(strGroups, IT) Then

wshNetwork.MapNetworkDrive "i:", "\\pways50-fs1\IT"
'

ElseIf InStr(strGroups, CORPORATE) Then

wshNetwork.MapNetworkDrive "x:", "\\pways50-fs1\corporate"

ElseIf InStr(strGroups, SERVICES) Then

wshNetwork.MapNetworkDrive "s:", "\\pways50-fs1\services"

ElseIf InStr(strGroups, UNIVERSITY) Then

wshNetwork.MapNetworkDrive "u:", "\\pways50-fs1\university"

End If

WScript.Echo "Script is complete."


Two objects for this project. 1) I would like one script to map network drives for my users. 2) After 8 hours i lose my connection to the server. I can either log back in or remap the drives. However i can not map the drives with the user that is logged in. i have to use the administrator account and password for the server.

Sorry for the log post.
thanks for your help.

Back to Hardware Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums