Solved

Logon Script help --Small Business Server 2003

Posted on 2009-07-06
5
227 Views
Last Modified: 2013-11-29

I have successfully created 3 VBS logon scripts utilizing GP based on all of the questions and answers I found in the knowledgebase on Experts-Exchange.

I having trouble with one more I need (yes I have reviewed the articles already posted, but to no avail).

Here is I ehat I need specifically:  I created a group called "CSRs" in Active directory.

If you are a member of "CSRs"
then
Map the following drive \\10.24.80.10\shared
Otherwise do nothing

Could somebody please provide me with the VBS code to perfrom the above?

Thank you,

John


0
Comment
Question by:CILLC
5 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 24785655
Why must it be a VBS script?  I use batch scripts for most things - they are simpler.

for you, you would get the IFMEMBER utility from the resource kit, put it on a network share or push it out to the clients and use that.

http://www.microsoft.com/downloads/details.aspx?FamilyID=07C2F6D7-815E-4FA0-9043-4E4635CCD417&displaylang=en
if not exist "%windir%\system32\ifmember.exe" copy "\\server\share\path\to\ifmember.exe" "%windir%\system32"
 

ifmember CSRs

if not errorlevel 1 goto CSRsDone

net use z: \\servername-fs03\data

:CSRsDone

Open in new window

0
 
LVL 6

Expert Comment

by:ou_dober
ID: 24785780
Here is what we use in our shop - of course modified.  Great script though.

Here is the link to the author's site.

http://www.rlmueller.net/LogonScriptFAQ.htm

Hope this helps.
' Logon3.vbs

' VBScript logon script program.

'

' ----------------------------------------------------------------------

' Copyright (c) 2002 Richard L. Mueller

' Hilltop Lab web site - http://www.rlmueller.net

' Version 1.0 - November 22, 2002

' Version 1.1 - February 19, 2003 - Standardize Hungarian notation.

' Version 1.2 - January 25, 2004 - Modify error trapping.

' Version 1.3 - July 31, 2007 - Escape any "/" characters in DN's.

'

' You have a royalty-free right to use, modify, reproduce, and

' distribute this script file in any way you find useful, provided that

' you agree that the copyright owner above has no warranty, obligations,

' or liability for such use.
 

Option Explicit
 

Dim objNetwork, objSysInfo, strUserDN

Dim objGroupList, objUser, objFSO

Dim strComputerDN, objComputer
 

Set objNetwork = CreateObject("Wscript.Network")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objSysInfo = CreateObject("ADSystemInfo")

strUserDN = objSysInfo.userName

strComputerDN = objSysInfo.computerName
 

' Escape any forward slash characters, "/", with the backslash

' escape character. All other characters that should be escaped are.

strUserDN = Replace(strUserDN, "/", "\/")

strComputerDN = Replace(strComputerDN, "/", "\/")
 

' Bind to the user and computer objects with the LDAP provider.

Set objUser = GetObject("LDAP://" & strUserDN)

Set objComputer = GetObject("LDAP://" & strComputerDN)
 

' Map a network drive if the user is a member of the group.

' Alert the user if the drive cannot be mapped.

If (IsMember(objUser, "Engineering") = True) Then

    If (MapDrive("M:", "\\FileServer\EngrShare") = False) Then

        MsgBox "Unable to Map M: to AdminShare"

    End If

End If
 

' Add a network printer if the computer is a member of the group.

' Make this printer the default.

If (IsMember(objComputer, "Front Office") = True) Then

    objNetwork.AddWindowsPrinterConnection "\\PrintServer\HPLaser2"

    objNetwork.SetDefaultPrinter "\\PrintServer\HPLaser2"

End If
 

' Clean up.

Set objNetwork = Nothing

Set objFSO = Nothing

Set objSysInfo = Nothing

Set objGroupList = Nothing

Set objUser = Nothing

Set objComputer = Nothing
 

Function IsMember(ByVal objADObject, ByVal strGroup)

    ' Function to test for group membership.

    ' objGroupList is a dictionary object with global scope.
 

    If (IsEmpty(objGroupList) = True) Then

        Set objGroupList = CreateObject("Scripting.Dictionary")

    End If

    If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then

        Call LoadGroups(objADObject, objADObject)

        objGroupList.Add objADObject.sAMAccountName & "\", True

    End If

    IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\" _

        & strGroup)

End Function
 

Sub LoadGroups(ByVal objPriObject, ByVal objADSubObject)

    ' Recursive subroutine to populate dictionary object objGroupList.
 

    Dim colstrGroups, objGroup, j
 

    objGroupList.CompareMode = vbTextCompare

    colstrGroups = objADSubObject.memberOf

    If (IsEmpty(colstrGroups) = True) Then

        Exit Sub

    End If

    If (TypeName(colstrGroups) = "String") Then

        ' Escape any forward slash characters, "/", with the backslash

        ' escape character. All other characters that should be escaped are.

        colstrGroups = Replace(colstrGroups, "/", "\/")

        Set objGroup = GetObject("LDAP://" & colstrGroups)

        If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _

                & objGroup.sAMAccountName) = False) Then

            objGroupList.Add objPriObject.sAMAccountName & "\" _

                & objGroup.sAMAccountName, True

            Call LoadGroups(objPriObject, objGroup)

        End If

        Set objGroup = Nothing

        Exit Sub

    End If

    For j = 0 To UBound(colstrGroups)

        ' Escape any forward slash characters, "/", with the backslash

        ' escape character. All other characters that should be escaped are.

        colstrGroups(j) = Replace(colstrGroups(j), "/", "\/")

        Set objGroup = GetObject("LDAP://" & colstrGroups(j))

        If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _

                & objGroup.sAMAccountName) = False) Then

            objGroupList.Add objPriObject.sAMAccountName & "\" _

                & objGroup.sAMAccountName, True

            Call LoadGroups(objPriObject, objGroup)

        End If

    Next

    Set objGroup = Nothing

End Sub
 

Function MapDrive(ByVal strDrive, ByVal strShare)

    ' Function to map network share to a drive letter.

    ' If the drive letter specified is already in use, the function

    ' attempts to remove the network connection.

    ' objFSO is the File System Object, with global scope.

    ' objNetwork is the Network object, with global scope.

    ' Returns True if drive mapped, False otherwise.
 

    Dim objDrive
 

    On Error Resume Next

    If (objFSO.DriveExists(strDrive) = True) Then

        Set objDrive = objFSO.GetDrive(strDrive)

        If (Err.Number <> 0) Then

            On Error GoTo 0

            MapDrive = False

            Exit Function

        End If

        If (objDrive.DriveType = 3) Then

            objNetwork.RemoveNetworkDrive strDrive, True, True

        Else

            MapDrive = False

            Exit Function

        End If

        Set objDrive = Nothing

    End If

    objNetwork.MapNetworkDrive strDrive, strShare

    If (Err.Number = 0) Then

        MapDrive = True

    Else

        Err.Clear

        MapDrive = False

    End If

    On Error GoTo 0

End Function

Open in new window

0
 
LVL 2

Accepted Solution

by:
Archonaus earned 500 total points
ID: 24785863
VBS offers so much more flexibility for scripting than batch files, though they do have their occasional uses...

Anyway, here is the same function in VBscript.  It checks if the drive is already there and maps accordingly.  You can change the variables at the top to change drive letter, path and the group you want to lookup.

If you want to disable the popup messages (good for testing but annoying otherwise) just comment out the 3 lines that have Msgbox at the start by putting a ' at the beginning.

Hope you like it!

P.s.  I wrote it as a Subroutine - Drivemapper, so the core functionality can easily be inserted and used in other scripts.
Option Explicit
 

Dim strGroup, strDrive, strPath

Dim objNetwork, objDrives, ADSysInfo, objUser, colGroups, objGroup, groupMember
 

strGroup = "CSRs"

strDrive = "V:"

strPath = "\\10.24.80.10\shared"
 

Set objNetwork = WScript.CreateObject("WScript.Network")

Set objDrives = objNetwork.EnumNetworkDrives
 

Set ADSysInfo = CreateObject("ADSystemInfo")

Set objUser = GetObject("LDAP://" & ADSysInfo.UserName)

Set colGroups = objUser.Groups
 

For Each objGroup in colGroups

    

    	groupMember = objGroup.CN

	

	If InStr(groupMember, strGroup) Then
 

	DriveMapper strDrive, strPath

	

	End If
 

Next
 

Sub DriveMapper(sDrive, sShare)

    Dim i

    For i = 0 to objDrives.Count -1 Step 2

    if LCase(sDrive) = LCase(objDrives.Item(i)) then

        if not LCase(sShare) = LCase(objDrives.Item(i+1)) then

            objNetwork.RemoveNetworkDrive sDrive, true, true

        Else

            Msgbox (Now() & ": Success: Connect """ & sDrive & """ to share """ & sShare & """ (previously connected)")

            Exit Sub

        End if

    End if

    Next

    on error resume next

    objNetwork.MapNetworkDrive sDrive, sShare

    If Err.Number = 0 Then

        Msgbox (Now() & ": Success: Connect """ & sDrive & """ to share """ & sShare & """")

    else

        Msgbox (Now() & ": Failed: Connect """ & sDrive & """ to share """ & sShare & """")

    end if

    on error goto 0

End Sub

Open in new window

0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 24786001
VBS scripts have their use, but batch files are simpler, in MOST cases shorter, and easier for most people to understand.  
0
 

Author Closing Comment

by:CILLC
ID: 31600183
Worked Perfectly.

Thank you,

John
0

Featured Post

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

Because virtualization becomes more and more common, and, with Microsoft Hyper-V included in Windows Server at no additional costs, and, most server hardware nowadays is more than capable of running a physical Small Business Server (SBS) 2008 or 201…
I’m often asked about newer and larger USB drives connected to SBS2008 and 2011 failing Windows Server Backup vs the older USB drives not failing. As disk space continues to grow and drive technology change SBS2008 and some SBS2011 end up with the f…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now