Batch file - Window 7 Help

Bob Stamm
Bob Stamm used Ask the Experts™
on
Experts,
I have users now with Windows XP and Window 7.  Need help to write this batch program for users to copy file in "Program Files or Program Files(86).  

Below is my current batch file.

Thanks,
Bob

rem '
copy "\\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd\ConstructionDatabase.mde" "c:\Program Files\AGOC\ConstructionDatabase\"
@ echo off
pause
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I have another suggestion.

Use robocopy instead. It's faster and detects file level changes at a directory level.

I would map your drive letter first:

net use Z: \\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd

robocopy "Z:\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd" c:\Program Files\AGOC\ConstructionDatabase" /MIR /R:0

Make sure you test the destination path with something like this before you implement as a production script:

robocopy "Z:\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd" c:\test" /MIR /R:0
Bob StammOperations Manager

Author

Commented:
Will this place the files in either the Program Files or Program Files(86) depending on the  user?
It only looks for the source and destination. If you prefer to create a folder within one of the Program Files directory as a destination that is fine.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
Windows 7 protects the Program Folders and a copy into these folders will usually result in a UAC permission prompt. That may prevent your batch file from working without intervention.

Can you put your database somewhere else beside Program Folders?

.... Thinkpads_User
Bob StammOperations Manager

Author

Commented:
Not easily to change location.  I have ~ 80 users in our company setup.  Only a few have been updated to Windows 7.
Does each user require a unique copy of the database for their own profile?
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
Windows 7 is totally different from XP with respect to Program Folders. Going forward, you will need to deal with this.

In the meantime, Task Scheduler can provide elevated permissions to run programs, so you should look at Task Scheduler.

.... Thinkpads_User
Thinkpads is right, you may end up with UAC or Access denied error, but you may also have already over-ridden these permissions.

What you're actually trying to do is determine if the folder C:\Program Files (x86)\ exists and has content.  THis is easy (even if Program Files is on Drive D:) as this information is stored in the Environment Variables of the PC you're copying to.

If you run a command prompt on the PC that is to recieve the files, and type:

SET

...and then press Return, you'll see all the environment variables.  These can be read in a batch file by surrounding them with % signs.

 So your batch file could look like this:

@Echo OFF
CLS
Echo Testing...
If exist "%programfiles(x86)%\*.*" GOTO X86

REM Files should go in %programfiles% (i.e. 32-bit PC)

copy "\\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd\ConstructionDatabase.mde" "%programfiles%\AGOC\ConstructionDatabase\"

GOTO Done

:x86
REM Files should go in %programfiles(x86)% (i.e. 64-bit PC)

copy "\\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd\ConstructionDatabase.mde" "%programfiles(x86)%\AGOC\ConstructionDatabase\"

:Done
Echo End of Batch File
Bob StammOperations Manager

Author

Commented:
I made a couple of changes and this seems to work fine. I will award points after I see if there are any additional comments.


@Echo OFF
CLS
Echo Testing...

If exist "c:\Program Files (x86)\*.*" GOTO X86
Echo Found Program Files
REM Files should go in %Program Files% (i.e. 32-bit PC)
copy "\\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd\ConstructionDatabase.mde" "c:\Program Files\AGOC\ConstructionDatabase\"

GOTO Done

:x86
REM Files should go in %Program Files (x86)% (i.e. 64-bit PC)
Echo Found Program Files (x86)
copy "\\agc01.com\agc-crp\crpglobal\everyone\NewFrontEnd\ConstructionDatabase.mde" "c:\Program Files (x86)\AGOC\ConstructionDatabase\"

:Done
Echo End of Batch File
pause
No more comments, are we to assume it's working?
Bob StammOperations Manager

Author

Commented:
Solution put me on right path.  I posted my final version specific to my needs.

Thanks,
Bob

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial