Script to authenticated the user, create folders, copy files and then launch executable.

Posted on 2014-08-05
Last Modified: 2014-08-06
Hey Experts,

I need a LOGIN Batch or VB Script to perform the following actions, in order:

1. Look in "C:\Users.Lights" DIR for a folder with the authenticated users's name on it.

2. IF there isn't a folder with it's %username% within "C:\Users.Lights", create one. IF it does exist, go to next step.

3. Look for a folder called "Lights" within "C:\Users.Lights\%username%" DIR,

4. IF there isn't is a folder called "Lights" is not found in "C:\Users.Lights\%username%" DIR, then copy the Lights folder from "C:\RDS.Setup" to "C:\Users.Lights\%username%".

5. Copy C:\RDS.Setup\PROD\*.exe C:\Users.Lights\%username%\Lights\ ** Overwrite existing EXE's **

6. Map network Drive " L:\ " to \\Server\Light$

7. Finally Launch Program located at: "C:\Users.Lights\%username%\Lights\Lights.exe"

7. END
Question by:Merrell
    LVL 1

    Author Comment

    I came up with this:

    CD C:\Users.Lights
    IF EXIST C:\Users.Lights\%username% (goto LIGHTSFOLDERS) ELSE (goto MKDIRUSER)
    MKDIR %username%
    IF EXIST C:\Users.Lights\%username%\Lights (goto COPYLIGHTS) ELSE (goto MKDIRLIGHTS)
    cd C:\Users.Lights\%username%
    COPY C:\RDS.Setup\Lights\*.* C:\Users.Lights\%username%\Lights
    COPY C:\RDS.Setup\PROD\*.exe C:\Users.Lights\%username%\Lights
    Net Use H: \\dctucson\light$
    CD C:\Users.Lights\%username%\Lights

    Open in new window

    ....but I would LOVE is the COPY PROD EXE portion of the script to have a little intelligence. If the EXE files in PROD were newer than the C:\USERS.LIGHTS\%username$\Lights, then replace. If not, then move on.... Thoughts?
    LVL 82

    Accepted Solution

    Try it with this; it uses robocopy.exe (part of the OS since Vista/Server 2008), which will by default only copy files if they don't exist in the same version in the target folder yet. You could use xcopy.exe with the /d switch, but xcopy has been declared deprecated, and Microsoft recommends to use robocopy (which is far better than xcopy):
    @echo off
    set BaseFolder=C:\Users.Lights
    set UserFolder=%BaseFolder%\%UserName%
    set LightsFolder=%UserFolder%\Lights
    set SetupFolder=C:\RDS.Setup\Lights
    set ProdFolder=C:\RDS.Setup\PROD
    if not exist "%UserFolder%" (
    	md "%UserFolder%"
    if not exist "%LightsFolder%" (
    	robocopy.exe "%SetupFolder%" "%LightsFolder%" *.* /r:0 /w:0
    robocopy.exe "%ProdFolder%" "%LightsFolder%" *.exe /r:0 /w:0
    net.exe use H: /delete >NUL 2>&1
    net.exe use H: "\\dctucson\light$" /persistent:no
    start "" /D "%LightsFolder%" "%LightsFolder%\Lights.exe"

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    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

    18 Experts available now in Live!

    Get 1:1 Help Now