?
Solved

VBS login sample

Posted on 2007-11-29
15
Medium Priority
?
1,151 Views
Last Modified: 2010-04-21
I was recently given the login script sample below for a previous question and it works great.  I am now looking to add to the login script and was looking for help on the syntax.  I'm looking to map a drive based on a user being in a specific group in AD.  I'm sure it's possible.  Something like if you're part of the general ledger group then map a drive to the general ledger share.  Any help would be greatly appreciated.

Thanks...

With a VBS file, you can use the WSH Network object to return the username, so you can use the same approach as a Batch file's %username% value.

Dim wshNetwork, objFSO
Set wshNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.DriveExists("h:") = True Then wshNetwork.RemoveNetworkDrive "h:"
If objFSO.DriveExists("m:") = True Then wshNetwork.RemoveNetworkDrive "m:"
If objFSO.DriveExists("o:") = True Then wshNetwork.RemoveNetworkDrive "o:"
If objFSO.DriveExists("s:") = True Then wshNetwork.RemoveNetworkDrive "s:"
wshNetwork.MapNetworkDrive "h:", "\\filesrv\users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "m:", "\\filesrv\data"
wshNetwork.MapNetworkDrive "o:", "\\filesrv\masters"
wshNetwork.MapNetworkDrive "s:", "\\filesrv\shared"
WSCript.Quit
0
Comment
Question by:nyceuser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
15 Comments
 
LVL 5

Expert Comment

by:usarian
ID: 20375533




Const PRODUCTION     	= "cn=plant floor users"
Const ADMINISTRATORS	= "cn=domain admins"
Const MANAGERS 		= "cn=production managers"
 
Set wshNetwork = CreateObject("WScript.Network")
 
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
 
strGroups = LCase(Join(CurrentUser.MemberOf,""))
 
wshNetwork.RemoveNetworkDrive "F:", True, True
 
IF InStr(strGroups, PRODUCTION) Then wshNetwork.MapNetworkDrive "F:", "\\{server}\{folder}"

Open in new window

0
 
LVL 5

Expert Comment

by:usarian
ID: 20375559
I found that I had to remove the network drive before adding it or I would get an error, and I also had to put strGroup =  "cn=default" in case the join returned no results, but that's all just error catching stuff.

Usarian
0
 

Author Comment

by:nyceuser
ID: 20375982
Would you be able to explain what each line does in the script you provided (since I'm not a VB guy)?  Also, does it matter where in the script I put these additional lines?

Thanks...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:usarian
ID: 20376703
Try using this for your logon script:
Dim wshNetwork, objFSO
Set wshNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) 
If objFSO.DriveExists("h:") = True Then wshNetwork.RemoveNetworkDrive "h:"
If objFSO.DriveExists("m:") = True Then wshNetwork.RemoveNetworkDrive "m:"
If objFSO.DriveExists("o:") = True Then wshNetwork.RemoveNetworkDrive "o:"
If objFSO.DriveExists("s:") = True Then wshNetwork.RemoveNetworkDrive "s:"
If objFSO.DriveExists("f:") = True Then wshNetwork.RemoveNetworkDrive "f:"
wshNetwork.MapNetworkDrive "h:", "\\filesrv\users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "m:", "\\filesrv\data"
wshNetwork.MapNetworkDrive "o:", "\\filesrv\masters"
wshNetwork.MapNetworkDrive "s:", "\\filesrv\shared"
strGroups = LCase(Join(CurrentUser.MemberOf,""))
IF InStr(strGroups, "cn=general ledger") Then wshNetwork.MapNetworkDrive "f:", "\\filesrv\general ledger"
WSCript.Quit

Open in new window

0
 

Author Comment

by:nyceuser
ID: 20377201
Ok... I made the appropriate changes and I think I'm almost there.  I'm getting the following error from line 15:

Line: 15
Char: 1
Error: Type mismatch : 'Join'
Code: 800A000D
Source: Microsoft VBScript runtime error

Any ideas?

Thanks for you help.
0
 

Author Comment

by:nyceuser
ID: 20377352
I figured out that if the user is part of more than one group the script processes but doesn't map the drive relating to the group membership.  It maps all other drives.  I'm sure I have something mixed up here.

Any ideas?
0
 

Author Comment

by:nyceuser
ID: 20377468
Ok... I got it working so it maps the drive for the membership but it only works if the user is part of more than 1 group.  I'm sure there's different syntax that I can use that won't matter how many groups the user is part of.
0
 
LVL 5

Expert Comment

by:usarian
ID: 20377556
Quick FYI, the "cn=blablabla" has to be lowercase.

If you haven't figure out the 1 group thing yet, post your code and I will take a look.
0
 

Author Comment

by:nyceuser
ID: 20377671
I haven't figured out the 1 group thing yet.  Below is the current script.

Dim wshNetwork, objFSO
Set wshNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
If objFSO.DriveExists("f:") = True Then wshNetwork.RemoveNetworkDrive "f:"
If objFSO.DriveExists("h:") = True Then wshNetwork.RemoveNetworkDrive "h:"
If objFSO.DriveExists("i:") = True Then wshNetwork.RemoveNetworkDrive "i:"
If objFSO.DriveExists("s:") = True Then wshNetwork.RemoveNetworkDrive "s:"
wshNetwork.MapNetworkDrive "f:", "\\filesrv\data"
wshNetwork.MapNetworkDrive "h:", "\\filesrv\users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "i:", "\\filesrv\groupshares\installs"
wshNetwork.MapNetworkDrive "s:", "\\filesrv\groupshares"
strGroups = LCase(Join(CurrentUser.MemberOf,""))
IF InStr(strGroups, "cn=business systems2") Then wshNetwork.MapNetworkDrive "g:", "\\filesrv\data\groupshares\genledger"
end if
WSCript.Quit
0
 
LVL 5

Expert Comment

by:usarian
ID: 20378788
Well, what I would do atthis point is check the contents of the string variable.
To do that, put msgbox(strGroups) between the "strGroups =" line and the "IF InStr(strGroups"  line.
Make sure the text "cn=business systems2" shows up and is identical (spaces and all).

Also, get rid of the END IF right above WScript.Quit
0
 

Author Comment

by:nyceuser
ID: 20382864
Ok...  added the additional line in and everything looks OK.  Got rid of the END IF.  Still same result.  As soon as I take the user out of one of the groups so he only belongs to one group the script fails with the type mismatch: 'Join' error.
0
 
LVL 5

Accepted Solution

by:
usarian earned 1000 total points
ID: 20383289
Try replacing:
strGroups = LCase(Join(CurrentUser.MemberOf))
    with
For each oGroup in CurrentUser.Groups
  strGroups = strGroups & Lcase(oGroup.name)
next


0
 

Author Comment

by:nyceuser
ID: 20383474
This is the script now.  Not sure if I have it right.  It processes through without any errors but does not map the g: drive based on group membership

Dim wshNetwork, objFSO
Set wshNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set Currentuser = GetObject("LDAP://" & ADSysInfo.UserName)
If objFSO.DriveExists("f:") = True Then wshNetwork.RemoveNetworkDrive "f:"
If objFSO.DriveExists("h:") = True Then wshNetwork.RemoveNetworkDrive "h:"
If objFSO.DriveExists("i:") = True Then wshNetwork.RemoveNetworkDrive "i:"
If objFSO.DriveExists("s:") = True Then wshNetwork.RemoveNetworkDrive "s:"
wshNetwork.MapNetworkDrive "f:", "\\filesvr\data"
wshNetwork.MapNetworkDrive "h:", "\\filesvr\users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "i:", "\\filesvr\groupshares\installs"
wshNetwork.MapNetworkDrive "s:", "\\filesvr\groupshares"
For each oGroup in CurrentUser.Groups
      strGroups = strGroups & Lcase(oGroup.name)
next
IF InStr(strGroups, "cn=bsg") Then wshNetwork.MapNetworkDrive "g:", "\\filesvr\data\groupshares\genledger"
WSCript.Quit
0
 

Author Comment

by:nyceuser
ID: 20383576
Looks like it's working now.  I think I had to wait until the changes took affect.  Thanks for your help... It now seems to work great.

Thanks again.  You're the best!
0
 

Author Closing Comment

by:nyceuser
ID: 31411723
Great job... saved me a lot of work and research.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question