Solved

Logon scripts for Windows 2003

Posted on 2004-09-17
7
142 Views
Last Modified: 2010-08-05
Hello.. I am using logon scripts for the first time.

My AD has some Global Groups under USERS which include the groups "Technical", and "Staff". These groups have access to different folders which I want mapping automatically on login. I have created and shared the fodlers with appropriate permissions / security and tested them.. all ok.

I now want a script that looks at the person logging on, maps them a home drive (this bit works), and then finds out if they are a member of a certain group (you CAN belong to more than one) and give them the appropriate mapping..

I can successfully map a drive WITHOUT a check, thats easy enough..

Here is the script thus far

Const STAFF                    = "CN=Staff"
Const TECHNICAL             = "CN=Technical"

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "H:", "\\server001\Profiles\" & wshNetwork.UserName & "\Documents"

Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))

If InStr(strGroups, TECHNICAL) Then

wshNetwork.MapNetworkDrive "S:", "\\server001\Software\"

ElseIf InStr(strGroups, STAFF) Then

wshNetwork.MapNetworkDrive "I:", "\\Server\Business\"

End If

It does not error at all, maps the H drive OK, just does not map the other drive(s).. I have logged on as a usre in the TECHNICAL group for this..

any help appreciated
0
Comment
Question by:mvwmail
[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
7 Comments
 
LVL 10

Expert Comment

by:jhautani
ID: 12083302
Almost similar problem was here:
http://www.experts-exchange.com/Operating_Systems/Windows_Server_2003/Q_21130336.html
See if it provides you a solution.
0
 
LVL 6

Expert Comment

by:tanelorn
ID: 12083319
hi,

try this,  but change the servers and drive letters and the server names to suit
its fairly easy to follow
  this is the logon script that I use.  I like it because I can add subroutines into it, and call them from the top by adding a call to the function

Hope this helps.
T

'==========================================================================
'
' NAME: adc_logon.vbs
'
' AUTHOR: xxxxxxxxxxxxxxxxxxxx
' DATE  : 6/05/2003
'
' COMMENT: This file must be copied to all domain controlers
'
'==========================================================================
On Error Resume Next
Dim WshNetwork, strUser, Domain, WshShell, Group

' Get the User ID
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Domain = WSHNetwork.UserDomain   'nUser means data from Network Object
strUser = ""
While strUser = ""
      strUser = WSHNetwork.UserName
Wend

'Call Main procedure to process the user groups information
call main()

' End of logon script
'****************************************************************************
'****************************************************************************


'*************** sub procedures and Functions *******************************

Public Sub Main()

  'Main loop to detect group that user belongs to
 
  Set objUser = GetObject("WinNT://" & Domain & "/" & strUser & ",user")
  For Each Group In objUser.groups
    Select Case Group.Name
            

      Case "Staff"
              Call staff()
            Case "technical"
              Call technical()
       
    End Select
  Next 'Group

  Set objUser = Nothing
                  
End Sub
'****************************************************************************
Sub staff()

 
Set fso = CreateObject("Scripting.FileSystemObject")

if fso.FolderExists("C:\Documents and Settings") Then

 
      MapDrive "h:", "\\eadc-fs001\home1\" & strUser

else
      MapDrive "h:", "\\eadc-fs001\home1"

End If
Set fso = Nothing


  MapDrive "P:", "\\eadc-fs001\projects1"
  MapDrive "S:", "\\eadc-fs001\shared1"
 

End Sub
'****************************************************************************

Sub technical()

 

  MapDrive "K:", "\\eadc-fs001\acct"

 

End Sub
'****************************************************************************

'****************************************************************************
Sub MapDrive(strDrive,strShare)

      On Error Resume Next
      WSHNetwork.MapNetworkDrive strDrive, strShare

      If Err.Number Then

            WSHNetwork.RemoveNetworkDrive strDrive
            WSHNetwork.MapNetworkDrive strDrive, strShare

      End If
            
End Sub
'****************************************************************************
'****************************************************************************

'End of SubProcedures and Functions
0
 
LVL 3

Author Comment

by:mvwmail
ID: 12083336
Looks good... I will look at both later as I am not with the server right now... many thanks
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 6

Expert Comment

by:tanelorn
ID: 12083344
you can also add more groups if you want by adding a case statement, and a call to a new function for the new group..
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12083386
Two additional options:

1.  If you create an OU for each group and place the users there, you can use Active Directory login scripts and anyone in that OU will get access to that drive (through the AD login script).  This COULD be done for users in more than one group, but that can get messy as you'd need to create sub OUs within each OU.

2.  Use IFMEMBER - available from Microsoft here: http://www.microsoft.com/windows2000/techinfo/reskit/tools/new/ifmember-o.asp - this will do what you want - I used it before myself, only not recently enough to give you exact syntax here.
0
 
LVL 3

Author Comment

by:mvwmail
ID: 12088515
Tanilorn

Tried your script.. no erros, but still no mapped drives..

I have confirmed all spelling, capilised where necessary.. even rtied moving the Group around to various places in AD, not that this makes a difference as the group can be anywhere really so long as it is under the domain..

Not a sausage.. not even an error..

Argh!
0
 
LVL 6

Accepted Solution

by:
tanelorn earned 300 total points
ID: 12101304
Hi,


please  put a  single quote in front of the "On Error Resume Next"
where ever you see them.  what this tells the script to do is to ignore errors and keep going. (without erroring out...) the single quote is a comment marker.   make the edit and run it again from your desktop.

please post your script, and I'll see If I can find anything.  if you only have 2 groups, it shouldn't be that complicated.

Tanelorn
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In order to fulfill our mission of inspiring learning in the technology community, Experts Exchange is launching a Course of the Month program. Premium and Team Account members will have access to one course per month as a part of their membership, …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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