Check EXE version in a batch file and if need be replace with another

Posted on 2008-11-19
Last Modified: 2012-05-05
I want to replace a file tswpfwrp.exe in Windows\System32 folder if it is an older version then the one I am replacing it with, otherwise, I don't want the batch file to run.

Below is an example of what I am trying to achieve, however, I don't know much about batchfile creation so the below example is not functional. Please help me create an effective batch file:

IF EXIST "C:\WINDOWS\system32\tswpfwrp.exe VER 3.0.6920.1201" goto lable1
IF NOT EXIST "C:\WINDOWS\system32\tswpfwrp.exe VER 3.0.6920.1201" goto lable2

echo Current Version exists
goto exit

copy \\ourdomain\dfs\SoftwareInstall\dotNetFramework\tswpfwrp >> c:\C:\WINDOWS\system32\

goto exit

Question by:SCRLPB
    LVL 21

    Accepted Solution

    XCOPY /d will only copy if the file is newer than the destination.

    xcopy /d /y \\ourdomain\dfs\SoftwareInstall\dotNetFramework\tswpfwrp C:\WINDOWS\system32\*.*
    LVL 8

    Expert Comment

    With a batch file I do not think this is possible without some other third party utility, however you can accomplish this with vbscript like

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Wscript.Echo objFSO.GetFileVersion("c:\windows\system32\notepad.exe")


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Numerous times I have been asked this questions that what is it that makes my machine log on so slow, there have been cases where computers took 23 minute exactly after taking password and getting to the desktop. Interesting thing was the fact th…
    If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    732 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

    21 Experts available now in Live!

    Get 1:1 Help Now