Announcement

Collapse
No announcement yet.

Question about "my" logon script.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about "my" logon script.

    I inherited the following script from the guy that worked here before me. I don't know much (anything) about VBS, but this script doesn't look right to me.
    It looks to me like he found and example online that worked and pasted it a few times and edited each individually.

    Code:
    On Error Resume Next
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
        Select Case strGroupName
            Case "SALES"
                objNetwork.MapNetworkDrive "S:", "\\Apollo\SALES DEPT"
        End Select
    Next
    
    On Error Resume Next
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
        Select Case strGroupName               
            Case "ADMINISTRATION" 
                objNetwork.MapNetworkDrive "F:", "\\Apollo\ADMINISTRATION DEPT"
        End Select
    Next
    
    On Error Resume Next
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
        Select Case strGroupName
            Case "CSG"
                objNetwork.MapNetworkDrive "T:", "\\Apollo\CSG Dept"
        End Select
    Next
    
    On Error Resume Next
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
        Select Case strGroupName
            Case "MAXWELL"
                objNetwork.MapNetworkDrive "P:", "\\Apollo\MAXWELL DEPT"
        End Select
    Next
    
    On Error Resume Next
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
        Select Case strGroupName               
            Case "TECH DEPARTMENT" 
                objNetwork.MapNetworkDrive "V:", "\\Apollo\TECH DEPT"
        End Select
    Next
    
    Dim WSHNetwork
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    
    WSHNetwork.MapNetworkDrive "M:", "\\Apollo\Maxwell"
    Was it really necessary to repeat the following for every line?
    Code:
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    Isn't that just a declaration of variables that you should only do once?

    Would this work fine? Could I slim it even more?
    Code:
    On Error Resume Next
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
        Select Case strGroupName
            Case "SALES"
                objNetwork.MapNetworkDrive "S:", "\\Apollo\SALES DEPT"
        End Select
    Next
    
    On Error Resume Next
    
        Select Case strGroupName               
            Case "ADMINISTRATION" 
                objNetwork.MapNetworkDrive "F:", "\\Apollo\ADMINISTRATION DEPT"
        End Select
    Next
    
    On Error Resume Next
    
        Select Case strGroupName
            Case "CSG"
                objNetwork.MapNetworkDrive "T:", "\\Apollo\CSG Dept"
        End Select
    Next
    
    On Error Resume Next
    
        Select Case strGroupName
            Case "MAXWELL"
                objNetwork.MapNetworkDrive "P:", "\\Apollo\MAXWELL DEPT"
        End Select
    Next
    
    On Error Resume Next
    
        Select Case strGroupName               
            Case "TECH DEPARTMENT" 
                objNetwork.MapNetworkDrive "V:", "\\Apollo\TECH DEPT"
        End Select
    Next
    
    Dim WSHNetwork
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    
    WSHNetwork.MapNetworkDrive "M:", "\\Apollo\Maxwell"

  • #2
    Re: Question about "my" logon script.

    Looks like your previous guy wasn't big on VBS either.

    From what I can see, it looks like the script maps various network drives based on group membership. To me certainly, it would be preferable to do this using Group Policy - is this something you have considered? Post back if you're not sure how to implement that and I'll post the steps you'd need to take. It's actually a much more elegant solution, and in my opinion much easier to manage and maintain.
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

    Comment


    • #3
      Re: Question about "my" logon script.

      Yes you can cut out a lot there. One loop with multiple Cases will do it.

      Code:
      On Error Resume Next
      
      Set objSysInfo = CreateObject("ADSystemInfo")
      Set objNetwork = CreateObject("Wscript.Network")
      
      strUserPath = "LDAP://" & objSysInfo.UserName
      Set objUser = GetObject(strUserPath)
      
      For Each strGroup in objUser.MemberOf
          strGroupPath = "LDAP://" & strGroup
          Set objGroup = GetObject(strGroupPath)
          strGroupName = objGroup.CN
      	
      	Select Case strGroupName
      		Case "GROUP1"
      		 objNetwork.MapNetworkDrive "G:", "\\blah\blah"
      		Case "GROUP2"
      		 objNetwork.MapNetworkDrive "H:", "\\blah\blah"
      	End Select
      Next

      Comment


      • #4
        Re: Question about "my" logon script.

        Originally posted by Garen View Post
        Yes you can cut out a lot there. One loop with multiple Cases will do it.

        Code:
        On Error Resume Next
        
        Set objSysInfo = CreateObject("ADSystemInfo")
        Set objNetwork = CreateObject("Wscript.Network")
        
        strUserPath = "LDAP://" & objSysInfo.UserName
        Set objUser = GetObject(strUserPath)
        
        For Each strGroup in objUser.MemberOf
            strGroupPath = "LDAP://" & strGroup
            Set objGroup = GetObject(strGroupPath)
            strGroupName = objGroup.CN
            
            Select Case strGroupName
                Case "GROUP1"
                 objNetwork.MapNetworkDrive "G:", "\\blah\blah"
                Case "GROUP2"
                 objNetwork.MapNetworkDrive "H:", "\\blah\blah"
            End Select
        Next
        If the first drive existed, wouldn't that give an error and jump to next and skip all the rest of the drives?
        Originally posted by gforceindustries View Post
        Looks like your previous guy wasn't big on VBS either.

        From what I can see, it looks like the script maps various network drives based on group membership. To me certainly, it would be preferable to do this using Group Policy - is this something you have considered? Post back if you're not sure how to implement that and I'll post the steps you'd need to take. It's actually a much more elegant solution, and in my opinion much easier to manage and maintain.
        If you have a good way to explain it, I'd love to hear. From what I gather, I'd want to make a single script for each group and then link it to the group, yes?

        Why do you think applying multiple scripts for multiple groups is better than one script for all users? Isn't that just more overhead on my part?

        Comment


        • #5
          Re: Question about "my" logon script.

          The "On Error Resume Next" will suppress any error messages but yes it won't remap it to the correct path. You could easily add some code int here to do that though.

          You can do this via GPO but theres some requirements.

          http://support.microsoft.com/kb/943729

          Comment


          • #6
            Re: Question about "my" logon script.

            Originally posted by Garen View Post
            Yes you can cut out a lot there. One loop with multiple Cases will do it.
            Absolutely.

            But note that "Select Case" statements are case sensitive! It would be better to force the group names to use only LowerCase characters.

            Also, the For Each strGroup in objUser.MemberOf loop by it self is not very reliable, as explained here: http://www.rlmueller.net/MemberOf.htm

            Here are two sample using the IsMember function:
            - http://www.rlmueller.net/IsMember4.htm
            - http://forums.petri.com/showpost.php...52&postcount=3
            the last script also support two extra options,
            # enForce the drive letter, if it is mapped to an other share it will disconnect from it.
            # reconnect the other mapping with any drive letter that is still available.

            \Rems


            requested the moderator to move this thread to scripting
            .
            Last edited by Rems; 11th November 2008, 00:34.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Question about "my" logon script.

              Originally posted by Kayden View Post
              If you have a good way to explain it, I'd love to hear. From what I gather, I'd want to make a single script for each group and then link it to the group, yes?
              Yes. I'll post back the steps required when I get back from lunch.

              Originally posted by Kayden View Post
              Why do you think applying multiple scripts for multiple groups is better than one script for all users? Isn't that just more overhead on my part?
              You could argue that it's less overhead as the scripts are so much simpler. No conditions to test, just pure functionality. You want something to happen? You put it in a script. You only want something to happen to some users? You only link that script to those users.

              If you use GPMC to manage your Group Policies (recommended - free download from Microsoft) then you can see at a glance what scripts are being applied to which users, without having to read through the script.

              As you've already pointed out, a script that maps 2 drives will bomb out if the first mapping fails, causing the others to fail too.

              Essentially, if you have one script with a bunch of IF statements, everybody executes the whole script, testing each IF statement in turn. If you have separate scripts for different users, there's no need for conditional testing and therefore the scripts run much faster.
              Gareth Howells

              BSc (Hons), MBCS, MCP, MCDST, ICCE

              Any advice is given in good faith and without warranty.

              Please give reputation points if somebody has helped you.

              "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

              "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

              Comment


              • #8
                Re: Question about "my" logon script.

                I too have the option to use GPO to set drives. However, GPO is flakey at times and it doesn't do what it should do. So I use login scripts as well. However I use AutoIT.

                All it is is management overhead. Do you want to have to manage many multiple scripts or have them wait a second longer to process a select/case statement?
                GoogleFu is strong with this one ^

                Comment

                Working...
                X