Jump to content

getFileVersion Version Comparison Function


Recommended Posts

Insert this pretty function at the bottom of registry_dos.js and have fun:

function fileVersionGreaterThan(fileVersion1,fileVersion2)
{
position="registry_dos.js";
whatfunc="fileVersionGreaterThan()";
var split1 = fileVersion1.toString().split("."), split2 = fileVersion2.toString().split(".");
for (var i = 0; i < split1.length; i++)
{
var split2item = parseInt(split2[i]);
if ((parseInt(split1[i]) > (isNaN(split2item)?0:split2item)))
return true;
}
return false;
}

Examples:

  • fileVersionGreaterThan("7.0",getFileVersion("c:\Program Files\Internet Explorer\iexplore.exe")) checks if a version of internet explorer previous to 7.0 is installed on the system.
  • fileVersionGreaterThan("3.0",getFileVersion("c:\Program Files\Mozilla Firefox\firefox.exe")) checks if a version of firefox previous to 3.0 is installed on the system.
  • fileVersionGreaterThan("3.0.0.7",getFileVersion("c:\Program Files\Mozilla Firefox\firefox.exe")) checks if a version of firefox previous to 3.0.0.7 is installed on the system.
  • fileVersionGreaterThan("11.0",getFileVersion("c:\Program Files\Windows Media Player\wmplayer.exe")) checks if a version of windows media player previous to 11 is installed on the system.
  • fileVersionGreaterThan("2.0.40115.0",RegKeyValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Silverlight\Version")) checks if a version of silverlight previous to 2.0.40115.0 is installed on the system
  • fileVersionGreaterThan("7.2.6001.788",getFileVersion("%SystemRoot%\System32\wuapi.dll")) checks if the windows update agent version is previous to 7.2.6001.788.

Edited by Francesco
Link to comment
Share on other sites


I noticed that getFileVersion returns 0 when there is an error (like when the file is missing) but the 0 is returned as an integer rather than a string. The function I wrote returns errors if both the parameters aren't strings so either the getFileVersion function is fixed by returning "0" or an empty string "" or my function has to be changed by replacing the var line with this:

var split1 = fileVersion1.toString().split("."), split2 = fileVersion2.toString().split(".");

I updated the function in first post with the changes.

Edited by Francesco
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...