Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Logon script - map drives based on group membership

Posted on 2004-10-27
4
Medium Priority
?
522 Views
Last Modified: 2009-02-27
I have a new Windows 2003 Server domain with NT and 2000 Clients.

I have a number of different groups set up which should each have different mapped drives to shares.

How can I create a logon script that will check the if the user is a member of certain groups and if so map relevent network drives?

An example script would be a great help, I am far from being a scripting guru....
0
Comment
Question by:STEVEO4
[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
  • 2
4 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 1000 total points
ID: 12419672

I recommend you use Kixtart for handling this. It's pretty easy to learn, well documented and definately a lot easier to work with than VBScript and a hundred times more capable than Batch files.

It ships as part of the Server Resource Kit, but I advise that you download the most recent release from:

www.kixtart.org

Once you have it this lot below is intended to teach you some of the basics of the language. Please let me know if you'd like more than I've written.

From the zip file copy kix32.exe into the NetLogon Share on one of your Domain Controllers. This one is the command processor, we need that for the script to run properly.

Next create the Logon.bat file. This is used to call the real logon script. Logon.bat should be entered as the script to run in your users profiles.

#Contents of Logon.bat#

kix32.exe logon.kix

Finally, the script itself.

#Contents of Logon.kix#

; Logon Script
;
; The ; is used to add comments to your code. These are just to make life easier
; for you and have no effect on the script.
;
; Created: 27/10/2004
; Modified: 27/10.2004

; Global Drive Mappings (the ones everyone gets)

; Mapping Drives is done with the Use command.
; Use syntax: Use "<Drive Letter>" "<Path>"

Use "L:" "\\Server\Share"

; Group Based Drive Mappings.
; We use an If Statement and the InGroup Function to figure out if we
; should be mapping the drive or not.
;
; If Statement syntax:
; If <Condition>
;    ... <Statements>
; EndIf
;
; InGroup returns true or false, you can use this with the If Statement.
; InGroup syntax:
; InGroup("<Group Name>")

If InGroup("Domain Admins")
    Use "K:" "\\Server\Share"
EndIf

; There's a lot more you can do with this script, one more really common example
; is adding Printers.

AddPrinterConnection("\\Server\Printer")

; As with the Use function that can be added to an If Statement to only add the printer
; if the user is in the right group.
0
 
LVL 5

Expert Comment

by:talphius
ID: 12422238
You can also use straight VB for this as well.  Here's a snipet from our scripts (OU & Domain names changed):

------------------
Set grpSysNet = GetObject("LDAP://test.local/cn=_DEPT_SYSTEMS_NETWORK,OU=Departments,OU=_Groups,DC=test,DC=local")

If grpSysNet.ismember(ADSPath) Then

    net.RemoveNetworkDrive "i:"
    net.MapNetworkDrive "i:", "\\test.local\dfsroot$\Systems"
End If
------------------

Basically it queries AD to see the membership of the Group (_DEPT_SYSTEMS_NETWORK in the example above), which is located under the _Groups\Departments OU of the domain test.local.  If the user is a member of that group then it will remove the mapped drive (in case the user already had one), and map it to the specified path (here drive I would be mapped to (\\test.local\dfsroot$\Systems).

Hope this helps - let me know if you need further assistance!
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 12422400

I didn't include removing a drive mapping with the example above, so just to keep it in line with Talphius's example (and so you can choose whichever you prefer) it's:

If InGroup("<Group Name>")
    Use "<Drive>" /d
    Use "<Drive>" "<Share Path>"
EndIf

One thing that I haven't had the opportunity to test is if Kix can map correctly to a DFS Share, one other expert had problems with it not performing the drive mapping in that situation.
0
 
LVL 104

Expert Comment

by:Sembee
ID: 12427485
A reskit utility called ifmember will also do this for you. This can be downloaded from Microsoft's web site.

http://www.amset.info/loginscripts/groups.asp

Sample (checking for membership of the group "Accounts")

:accounts
ifmember accounts
if not errorlevel 1 goto next
echo Connecting to Accounts...
net use N: \\server1\accounts$

:next

Simon.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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