Solved

Batch File To Add and Remove Files from Multiple Locations in a Mixed Enviroment

Posted on 2014-03-31
8
289 Views
Last Modified: 2014-05-04
Hi Experts,

We are migrating our business application to another server, as a result the following changes need to be applied to all PC's:

Shortcut Links to be added on Desktop (3)
Config files to be placed in applications config directory which will link to the shortcuts applied to the desktop
Start Menu Folder to be added which includes the shortcuts added to the desktop
Original Start Menu folder to be deleted

Now I have network shares put in place which includes the client config and the shortcuts, I have run the following batch file which has worked successfully for adding the shortcuts on the desktop:

@echo off
setlocal
set UserRoot=C:\Documents and settings
REM *** Process all profile folders:
for /d %%a in ("%UserRoot%\*.*") do call :process "%%a"
:: *** subroutine 'process' starts here:
:process
set UserFolder=%~1
echo Processing %UserFolder% ...
REM *** %UserFolder% now contains the folder name currently being processed.
REM *** Add your backup/deletion code between this line and the "goto :eof" at the end:
cd "%UserFolder%\Desktop\"
cd "%UserFolder%\Desktop\"
If exist "%UserFolder%\Desktop\Epicor2*" goto finish
copy "\\htukdc1\IT$\Epicor\Shortcuts\*" "%userprofile%\desktop\"
goto :eof

We are currently in a mixed environment with a combination of windows XP and Windows 7 machines, running both x86 and X64 operating systems.

I am not to savvy with scripting and was wondering whether it would be possible to enhance the script above to perform all actions required, windows 7 variables do not match up too well with XP variables and this has caused me grief :-(

Ideally I would like a single logon script to perform the above actions, your help is much appreciated, thanks in advance!

Regards,
0
Comment
Question by:HaywardTyler
8 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 39968267
Hi, I would think something like this is all you would need, which just checks for C:\Users (typically only exists on Windows 7 machines) and sets the UserRoot accordingly.

@echo off
setlocal
IF EXIST "C:\Users"
(
set UserRoot=C:\Users
)ELSE(
set UserRoot=C:\Documents and settings
)
REM *** Process all profile folders:
for /d %%a in ("%UserRoot%\*.*") do call :process "%%a"
:: *** subroutine 'process' starts here:
:process
set UserFolder=%~1
echo Processing %UserFolder% ...
REM *** %UserFolder% now contains the folder name currently being processed.
REM *** Add your backup/deletion code between this line and the "goto :eof" at the end:
cd "%UserFolder%\Desktop\" 
cd "%UserFolder%\Desktop\" 
If exist "%UserFolder%\Desktop\Epicor2*" goto finish
copy "\\htukdc1\IT$\Epicor\Shortcuts\*" "%UserFolder%\desktop\"
goto :eof

Open in new window


Regards,

Rob.
0
 

Author Comment

by:HaywardTyler
ID: 39968743
Hi Rob,

Thanks for your assistance, the above meets requirement 1, a colleague of mine advises that Dell Kace may be the answer to my problems, so will talk it through with him to attempt to find solution before I look at using a logon script.
0
 
LVL 26

Expert Comment

by:skullnobrains
ID: 39971669
i think the environment var %PROFILESFOLDER% should contain the proper location whatever the windows version
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 40026335
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40026336
At this stage, I believe my script in comment ID: 39968267 meets the user requirement.
0
 
LVL 26

Expert Comment

by:skullnobrains
ID: 40040420
won't work for a seven machine migrated from xp for example : the c:\users folders will exist but the accounts will be located in documents and settings.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

932 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

12 Experts available now in Live!

Get 1:1 Help Now