Script to swap out files in Program Files/Program Files (x86)

Discussion in 'Scripting' started by Elmer BeFuddled, Jul 13, 2013.

  1. Elmer BeFuddled

    Elmer BeFuddled MDL Novice

    Jun 11, 2010
    17
    2
    0
    #1 Elmer BeFuddled, Jul 13, 2013
    Last edited by a moderator: Apr 20, 2017
    I finally got this batch script to do what it's supposed to! The idea being is that the file to be changed may be in Program Files (x86) or Program Files, depending on system in use. I've just inherited a 32bit Win 7 laptop and I'd like to set up a minimal version of my 64bit desktop. Obviously some install folders have a different path.

    It checks to see if there is an AnyProgram0ldie.exe version in Program Files (x86) and/or Program Files and if so deletes it.
    Then take ownership of AnyProgram.exe in Program Files (x86) and/or Program Files.
    Rename AnyProgram.exe to AnyProgram0ldie.exe where it is found.
    Copy a new updated AnyProgram.exe to a folder where the "new" AnyProgram0ldie.exe now exists.
    Finally (optionally) run the program.

    Now, it does work. But I'm positive there has to be an easier way to do this!

    I change a lot of icons/add more icons to the exe files and change wording in some *.dll files to keep the context menu nice n thin. At re-install time the swapping of these files in/out is the only thing that has to be done manually.
    In a pique of boredom I thought I'd try to automate the process a bit.

    Would anyone care to enlighten me as to how it should have been actually written? Maybe with some explanations as to what the 'Ifs','Whys' and 'wherefores' actually do and mean?

    I'm actually wondering about the Takeown and Icacls lines. Are they not duplicating the same "action"?
    I'm also pretty certain some of the Full Path entries could be cut, or maybe not?
    Code:
    @echo off
    cls
    
    IF EXIST "C:\Program Files (x86)\Any Program\AnyProgram0ldie.exe" DEL "C:\Program Files (x86)\Any Program\AnyProgram0ldie.exe"
    
    IF EXIST "C:\Program Files (x86)\Any Program\AnyProgram.exe" TAKEOWN /F "C:\Program Files (x86)\Any Program\AnyProgram.exe"
    
    IF EXIST "C:\Program Files (x86)\Any Program\AnyProgram.exe" ICACLS "C:\Program Files (x86)\Any Program\AnyProgram.exe" /grant administrators:F /t
    
    IF EXIST "C:\Program Files (x86)\Any Program\AnyProgram.exe" REN "C:\Program Files (x86)\Any Program\AnyProgram.exe" "AnyProgram0ldie.exe"
    
    IF EXIST "C:\Program Files (x86)\Any Program\AnyProgram0ldie.exe" COPY "C:\USERS\%USERNAME%\DOCUMENTS\Any Program\AnyProgram.exe" "C:\Program Files (x86)\Any Program\AnyProgram.exe"
    
    IF EXIST "C:\Program Files (x86)\Any Program\AnyProgram.exe" start "" "AnyProgram.exe"
    
    IF EXIST "C:\Program Files\Any Program\AnyProgram0ldie.exe" DEL "C:\Program Files\Any Program\AnyProgram0ldie.exe"
    
    IF EXIST "C:\Program Files\Any Program\AnyProgram.exe" TAKEOWN /F "C:\Program Files\Any Program\AnyProgram.exe"
    
    IF EXIST "C:\Program Files\Any Program\AnyProgram.exe" ICACLS "C:\Program Files\Any Program\AnyProgram.exe" /grant administrators:F /t
    
    IF EXIST "C:\Program Files\Any Program\AnyProgram.exe" REN "C:\Program Files\Any Program\AnyProgram.exe" "AnyProgram0ldie.exe"
    
    IF EXIST "C:\Program Files\Any Program\AnyProgram0ldie.exe" COPY "C:\USERS\%USERNAME%\DOCUMENTS\Any Program\AnyProgram.exe" "C:\Program Files\Any Program\AnyProgram.exe"
    
    IF EXIST "C:\Program Files\Any Program\AnyProgram.exe" start "" "AnyProgram.exe"
    
    exit
    What you have here is an old dog trying to learn new tricks!

    TIA