[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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
0
Glenn M
Asked:
Glenn M
1 Solution
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now