Announcement

Collapse
No announcement yet.

vbScript login scripts erratic

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

  • vbScript login scripts erratic

    I seem to keep running into problems using vbscript as a logon script. They usually run correctly but sometimes they don't. Usually it's just that drives won't map. I think it has to do with some PC's having persistent drive maps even though I do a RemoveNetworkDrive first. Here's the rub: It works just fine when I execute it directly. They only have problems when running as logon scripts.

    Here is an example but this isn't the only one it has happened on. The only things in common between this and the others are AD login script processing and *ahem* Me. I believe it's one of those two. Also, I am open to any tips/suggestions on my script. I'm a newb with vbscript and like learning from pros.

    Moderator edit: added the script between [code] tags
    Code:
    '----------------------------------------------------------------------
    'Declare Globals
    '----------------------------------------------------------------------
    On Error Resume Next
    
    '----------------------------------------------------------------------
    'Create Object Collections
    '----------------------------------------------------------------------
    Set WshNet = WScript.CreateObject("Wscript.Network")
    Set objADSInfo = CreateObject("ADSystemInfo")
    Set fsoObject = CreateObject("Scripting.FileSystemObject")
    
    '----------------------------------------------------------------------
    'Setup Variables To Be Used
    '----------------------------------------------------------------------
    strUser = objADSInfo.Username
    Set strUprops = GetObject("LDAP://" & strUser)
    strDomain = LCase(WshNet.UserDomain)
    strDNSDomain = "blah.net"
    strGroups = LCase(Join(strUprops.MemberOf))
    strDC1 = "\\domainsvr." & strDNSDomain
    
    'strNBName = LCase(strUprops.sAMAccountName)
    'strHome = LCase(strUprops.HomeDirectory)
    'strDesc1 = LCase(strUprops.Description)
    'strDescArr = split(strDesc1,",")
    'strDesc = strDescArr(0)
    'Wscript.Echo strDesc
    '----------------------------------------------------------------------
    'Test Area
    '----------------------------------------------------------------------
    'Wscript.Echo strDept
    'MsgBox strDNSDomain & vbCrLf & strUser
    'MsgBox strHome & " " & strNBName
    'MsgBox Lcase(strUser)
    '----------------------------------------------------------------------
    'Start Running Subroutines
    '----------------------------------------------------------------------
    MapDrives()
    '----------------------------------------------------------------------
    'Subroutines executed by the lines above
    '----------------------------------------------------------------------
    Sub MapDrives()
        If InStr(Lcase(strUser), "my username") Then
            MsgBox "This is the MapDrives subroutine"
        End If
    
        'Clean Up Drives We Need To Use
        CleanDrive "F:"
        CleanDrive "G:"
        CleanDrive "H:"
        CleanDrive "L:"
        CleanDrive "M:"
        CleanDrive "O:"
        CleanDrive "T:"
        CleanDrive "V:"
        CleanDrive "X:"
        CleanDrive "Y:"
        
        'Start Mapping Drives
        WshNet.MapNetworkDrive "F:","\\blah-srv.blah.net\data"
        If Err <> 0 Then
            DisplayErrorInfo
        End If
        WshNet.MapNetworkDrive "O:","\\blah-srv.blah.net\office"
        If Err <> 0 Then
            DisplayErrorInfo
        End If
        WshNet.MapNetworkDrive "T:","\\srv-svr.blah.net\temp"
        If Err <> 0 Then
            DisplayErrorInfo
        End If
    
        'Map Conditional Drives
        If InStr(strGroups, "accounting") Then
            WshNet.MapNetworkDrive "H:","\\2000-app.blah.net\accounting"
        End If
        If InStr(strGroups, "cad_ws") Then
            WshNet.MapNetworkDrive "L:","\\blah-srv.blah.net\library"
            WshNet.MapNetworkDrive "V:","\\srv-svr.blah.net\cad"
        End If
        If InStr(strGroups, "cn=marketing department") Then
            WshNet.MapNetworkDrive "M:","\\mktingsvr.blah.net\data"
        End If
        If InStr(strGroups, "it department") Then
            WshNet.MapNetworkDrive "X:","\\srv-svr.blah.net\proj shared"
            WshNet.MapNetworkDrive "Y:","\\blah-srv.blah.net\itdept"
        End If
    End Sub
    '----------------------------------------------------------------------
    'CleanDrive Subroutine To Reduce Repetition
    '----------------------------------------------------------------------
    Sub CleanDrive(drv)
        If fsoObject.DriveExists(drv) Then
            WshNet.RemoveNetworkDrive drv
        End If
    End Sub
    '----------------------------------------------------------------------
    'Error Handling Routine
    '----------------------------------------------------------------------
    Sub DisplayErrorInfo
    
        WScript.Echo "Error:      : " & Err
        WScript.Echo "Error (hex) : &H" & Hex(Err)
        WScript.Echo "Source      : " & Err.Source
        WScript.Echo "Description : " & Err.Description
    End Sub
    '----------------------------------------------------------------------
    'The End
    '----------------------------------------------------------------------
    Last edited by Rems; 3rd March 2009, 23:43.

  • #2
    Re: vbScript login scripts erratic

    The "On Error Resume Next" statement should be placed especially in the 'Sub CleanDrive' subroutine in your script (How does the "On Error Resume Next" behave).

    You may also need to check the "Always wait for the network at computer startup and logon" option in Group Policy.

    \Rems

    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

    Working...
    X