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

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
LVL 2
Glenn MSystems Engineer / ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn MSystems Engineer / ManagerAuthor Commented:
I came up with this:


CD\
CD C:\Users.Lights
IF EXIST C:\Users.Lights\%username% (goto LIGHTSFOLDERS) ELSE (goto MKDIRUSER)


:MKDIRUSER
MKDIR %username%
goto LIGHTSFOLDERS

:LIGHTSFOLDERS
IF EXIST C:\Users.Lights\%username%\Lights (goto COPYLIGHTS) ELSE (goto MKDIRLIGHTS)
GOTO COPYLIGHTS

:MKDIRLIGHTS
cd C:\Users.Lights\%username%
MKDIR LIGHTS
GOTO COPYLIGHTS

:COPYLIGHTS
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
C:\Users.Lights\%username%\Lights\Lights.exe

Exit

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?
0
oBdACommented:
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
setlocal
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.