Announcement

Collapse
No announcement yet.

Login Script

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

  • Login Script

    Hi,

    I found this script (http://forums.petri.com/showthread.php?t=9607) on this site done by brain873 (Thanks you rock!).

    But I having trouble changing the disconnect all drives to just the drives I'm trying to map i.e. I, J, K, L, M, N etc etc

    Any Ideas???

    Code:
    ON ERROR RESUME NEXT
    Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, objNetwork, objNetwork1
    Set WSHShell = CreateObject("WScript.Shell")
    '--------------------- Drive Maps & Default Printer Settings ---------------------------
    '
    'DRIVE MAPPINGS UNC PATH Group with permissions to Drive
    '
    'DEPARTMENTAL MAPPINGS
    'I: \\server\Administration$ Administration
    'J: \\server\IT$ Tech
    'K: \\server\NewAccounts$ NewAccounts
    'L: \\server\SalesAndMarketing$ SalesAndMarketing
    'M: \\server\CarrierManagment$ CarrierManagement
    'N: \\server\CustomerService$ CustomerService
    '
    'COMMON MAPPINGS
    'E: \\server\share 
    'S: \\server\share2 
    '
    'USER MAPPINGS
    'H: \\server\%USERNAME%$ Individual Users (Active Directory)
    '
    Set WSHNetwork = CreateObject("WScript.Network")
     
    'Automatically find the domain name
    Set objDomain = getObject("ldap://rootDse")
    DomainString = objDomain.Get("dnsHostName")
    WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
     
    'Grab the user name
    UserString = WSHNetwork.UserName
     
    'Bind to the user object to get user name and check for group 
    memberships later
    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
     
    'Grab the computer name for use in add-on code later
    strComputer = WSHNetwork.ComputerName
     
    'Disconnect ALL mapped drives
    Set clDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to clDrives.Count -1 Step 2
    WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
    Next
     
    'Give the PC time to do the disconnect, wait 300 milliseconds
    wscript.sleep 300
     
    'Map drives
    WSHNetwork.MapNetworkDrive "p:", "\\server\users\" & UserString,True (COMMENTED FOR REFERENCE)
    WSHNetwork.MapNetworkDrive "e:", "\\server\share",True
    WSHNetwork.MapNetworkDrive "s:", "\\server\share2",True
     
    'Now check for group memberships and map appropriate drives
    For Each GroupObj In UserObj.Groups
    Select Case GroupObj.Name
     
    'Check for group memberships and take needed action
    Case "Administration"
    WSHNetwork.MapNetworkDrive "I:", "\\server\administration$",True
    Case "IT"
    WSHNetwork.MapNetworkDrive "J:", "\\server\it$",True
    Case "NewAccounts"
    WSHNetwork.MapNetworkDrive "K:", "\\server\newaccounts$",True
    Case "SalesAndMarketing"
    WSHNetwork.MapNetworkDrive "L:", "\\server\salesandmarketing$",True
    Case "CarrierManagement"
    WSHNetwork.MapNetworkDrive "M:", "\\server\carriermanagement$",True
    Case "CustomerService"
    WSHNetwork.MapNetworkDrive "N:", "\\server\customerservices$",True
    End Select
    Next
     
    'Clean Up Memory We Used
    Set UserObj = Nothing
    Set GroupObj = Nothing
    Set WSHNetwork = Nothing
    Set DomainString = Nothing
    Set WSHSHell = Nothing
    Set WSHPrinters = Nothing
    Set objNetwork = Nothing
    Set objNetwork1 = Nothing
     
    'Quit the Script
    wscript.quit
    Last edited by Dumber; 5th April 2009, 00:45.

  • #2
    Re: Login Script

    Originally posted by DThorne View Post

    But I having trouble changing the disconnect all drives to just the drives I'm trying to map i.e. I, J, K, L, M, N etc etc

    'Disconnect ALL mapped drives
    Set clDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to clDrives.Count -1 Step 2
    WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
    Next
    Change the scirpt to print the drives and quit. Look what you'll get and add some branching code that matches the output.

    Maybe something like the following works.
    Code:
    dim letter
    Set clDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to clDrives.Count -1 Step 2
    if (len(clDrives.Item(i))>0) then
      letter = left(clDrives.Item(1), 1)
      select case letter
        case "Q"
        case "T"
        ' list all other dirives you want to keep.
        case else
          WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
       end select
    end if
    next
    -vP

    Comment


    • #3
      Re: Login Script

      Thanks for that

      Can i not use below before mapping the drive:

      WSHNetwork.RemoveNetworkDrive "S:", True, True

      Comment


      • #4
        Re: Login Script

        I've added code tags around your script.
        Make sure you use correct formatting like tabs and so on to make a script more readable just like what vonPryz did.
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment

        Working...
        X