How do u create a logon script for drive mappings and to run an .exe ?

Posted on 2005-04-19
Last Modified: 2010-04-18
I am working in a mixed win2000/2003 server environment with mixed 2000/xp client machines.  
I need to create a logon script so that an ou of users have drive mappings setup and an .exe runs every time they logon.
The script will be deployed using group policy. I have no experience of writing scripts.

Please, can anyone help me?
Question by:gpersand
    LVL 8

    Accepted Solution

    ' Your script name


    Set WSHShell = CreateObject("WScript.Shell")
    Set WSHNetwork = CreateObject("WScript.Network")

    'Edit the next line with your domain name
    DomainString = "DomainName"
    UserString = WSHNetwork.UserName
    'Bind to the user object to get user name and check for group memberships later
    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

    'Synchronizes the time with Server our NTP Server
    WSHShell.Run "NET TIME \\Server /set /y"

    'Disconnect any drive mappings as needed.
    WSHNetwork.RemoveNetworkDrive "F:"

    'Give the PC time to do the disconnect, wait 300 milliseconds
    wscript.sleep 300

    'Map drives needed by all
    WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
    WSHNetwork.MapNetworkDrive "X:", "\\server\executables",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
        'In this example below, ADMIN and WORKERB are groups.
            Case "Admin"
                WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
            Case "WorkerB"
                WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
        End Select

    'Install Printers
    WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"

    'Remove an old printer
    WSHNetwork.RemoveWindowsPrinterConnection "\\ServerOld\HP5si"

    ' This section of script will prevent the baloon window that appears when printing
    ' to a network shared printer after XP Service Pack 2 is installed.

    Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
    WshShell.RegWrite Path, 0 ,"REG_DWORD"

    'Clean Up Memory We Used
    set UserObj = Nothing
    set GroupObj = Nothing
    set WSHNetwork = Nothing
    set DomainString = Nothing
    set WSHSHell = Nothing

    'Quit the Script
    LVL 5

    Expert Comment

    add the script in netlogon..

    u can do all this through group policy..

    Author Comment

    I deeply apologise for my late reply. I have recently moved home and have not had an internet connection.

    The script you have written is a bit too complicated making it difficult for me to understand how to use it properly.

    Could you give me a script in .bat format so I can add it to the netlogon share on a dc.
    All the script needs to do is map network drives.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
    The HP utility "HP Lights-Out Online Configuration Utility for Windows Server 2003/2008" could be of great use when it comes to remotely configure a HP servers ILO WITHOUT rebooting the server. We would only need to create and run scripts using thi…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    22 Experts available now in Live!

    Get 1:1 Help Now