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!

Help with a Logon script

Status
Not open for further replies.

zpetersen

MIS
Dec 29, 2003
58
US
User1 is a member of Group2 and Group4 and needs both the i: drive and p: drive. When the logon scrip runs the i: drive maps and none of the drives after that map. Now, I realize that I am using an If statement and from what I know once one of the conditions is met the statement stops. I need to to run through the whole list and map all necessary drives.

I checked out MarcD's logon script FAQ faq329-5798 and Im not having any luck getting that to do what I need it to.

HELP, PLEASE! :)

Code:
' ======================================================
' DEFINE AD GROUP CONSTANTS
' ======================================================
Const GROUP1 = "cn=group1"
Const GROUP2 = "cn=group2"
Const GROUP3 = "cn=group3"
Const GROUP4 = "cn=group4"

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

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "h:", "\\server\home\" & wshNetwork.UserName

' ======================================================
' MAP HOME DRIVE G:
' ======================================================

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "g:", "\\server\data"

' ======================================================
' MAP HOME DRIVE J:
' ======================================================

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "j:", "\\server\public"

' ======================================================
' 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, GROUP1) Then

	wshNetwork.MapNetworkDrive "i:", "\\server\data\folder"
	wshNetwork.MapNetworkDrive "k:", "\\server\data\folder"

ElseIf InStr(strGroups, GROUP2) Then

	wshNetwork.MapNetworkDrive "i:", "\\server\data\folder"

ElseIf InStr(strGroups, GROUP3) Then

	wshNetwork.MapNetworkDrive "i:", "\\server\data\folder"
	
ElseIf InStr(strGroups, GROUP4) Then

	wshNetwork.MapNetworkDrive "p:", "\\server\data\folder"
	
End If
 
I was just thinking, what if I split this thing into multiple If statements? I dont see why that wouldnt work. I'm gonna give that a shot. I'm still open to suggestions however.
 
You hit it. Just change your ElseIf's to If's.. otherwise only the first match executes.
 
Thanks for the reply Skie. I modified the script to use multiple If statements and I'm pretty sure its going to work just fine now.
 
Does anyone have a generic login script that maps drives AND printers based on AD group membership. Mainly printers...

MANY THANKS!!


Brandon
 
Have you tried to look at the FAQ area in this forum ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Brandon,

Heres some code that I have for future use in my logon scripts:

Code:
wshNetwork.AddWindowsPrinterConnection
"\\PrintServer\Printer"
wshNetWork.SetDefaultPrinter
"\\PrintServer\Printer"

Also, check out FAQ329-5798
 
Thanks- I have looked but I have yet to find a script that will map printers based on AD group membership. Tons of them out there for Drives- but not printers...??

Any advice?


THANKS!
Brandon
 
Use the logon script example that I have in my first post and just add the printer code listed above in with the drive mapping code.
 
zpetersen
I checked out MarcD's logon script FAQ FAQ329-5798 and Im not having any luck getting that to do what I need it to.

What are yo not getting it to do? If you enumerate the users group memberships and include an entry for each group name in the select case then you shoud be OK. Watch out for problems with case.

While VBScript commands may not be case sensitive, your values in the Case statement will be. For example:
Code:
test = "UPPERCASE"

Select Case test
	Case "uppercase"
		WScript.Echo "Found it anyway"
	Case "UPPERCASE"
		WScript.Echo "Found Upper Case"
End Select

You can force the comparrison in lower case like this
Code:
test = "UPPERCASE"

Select Case lcase(test)
	Case "uppercase"
		WScript.Echo "Found it anyway"
	Case "UPPERCASE"
		WScript.Echo "Found Upper Case"
End Select


I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top