Home

Results 1 to 2 of 2

Thread: How to compare Version Numbers saved as Strings in the Reg

Threaded View

  1. #1
    Join Date
    Feb 2008
    Location
    Raleigh, NC
    Posts
    6,466

    How to compare Version Numbers saved as Strings in the Reg

    Issue: When "Version" numbers are stored in the Registry, they are often stored as strings instead.
    String Comparisons Operations performed Numerical Values may not provide the desired Results.
    For Example the NUMBER '9' is numerically lower than the NUMBER '10'.
    However the STRING '9' is alphabetically higher the STRING '10'

    Theoretical Solution: The way to 'resolve' this issue is to "Zero-Pad" the strings so that the larger number is also alphabetically greater.
    For Example - '09' is both Numerically and Alphabetically lower than '10'

    It is also possible to "Zero-Pad" Version Numbers as well.
    The Version Number 10.19 is actually LOWER than Version Number 10.101, despite being alphabetically higher.
    These Version Numbers can be "Zero-Padded" to 10.019 and 10.101 so that the Minor Version number of "101" evaluates higher than Minor Version Number "19".

    ----
    Implementing the Solution:

    Attached is a batch file, though it is saved as a TXT file. (Rename StringVersion.txt to StringVersion.bat)
    The Purpose of the Batch File is to accept a Target Registry Value Containing a Version String as Input and Generate a Zero Padded Version String to a Defined Target Registry Value.
    It is recommended to create a New Registry Value instead of updating the Existing Value to avoid any possible issues in the event the software make use of the source version registry Value.

    SampleInputRegisty.txt is a Sample Registry File that demonstrates a possible source Registry Value to be used for Input.
    SampleOutputRegistry.txt is a Sample of a Zero Padded Version Value Created.

    This Script Requires 4 Input Parameters. Use Quotes if parameters include spaces.

    Parameter 1 is the Registry KEY to Read (Do not Confuse Key with Value)
    Parameter 2 is the Registry VALUE to Read
    Parameter 3 is the Target Output Registry Key (Do not Confuse Key with Value)
    Parameter 4 is the Target Output Registry Value
    If less than 4 Parameters are provided...The script will Exit.

    The Syntax to Generate the Output Keys from the Sample Keys above are the following:
    StringVersion.bat “HKLM\Software\ITHOWTO” “Version9” “HKLM\Software\It How To” “Version9String”
    StringVersion.bat “HKLM\Software\ITHOWTO” “Version10” “HKLM\Software\It How To” “Version10String”
    (Note: Version Numbers are Zero-Padded to 5 Places to account for possible 5 digit numbers in version strings.)

    The Input Values are the Following:
    [HKEY_LOCAL_MACHINE\SOFTWARE\ITHOWTO]
    "Version9"="9.5"
    "Version10"="10.1"

    In this Case, "Version9" is Alphanumerically Greater than "Version10" despite being Numberically Lower.

    The Zero Padded Output Values are the Following:
    [HKEY_LOCAL_MACHINE\SOFTWARE\It How To]
    "Version9String"="00009.00005.0000.0000"
    "Version10String"="00010.00001.0000.0000"

    Now "Version9" is BOTH numerically and alphanumerically lower than "Version10".


    To Use this Batch File in a Bundle to Check Versions….
    #1 – Create One Action to Run the Batch File to Generate a Zero-Padded Version String.
    #2 – Use the Zero-Padded Version String Registry Key as an Action Level System Requirement to Determine if the Software Should be Installed.


    (Note: This Post is to provide an interim solution to the following "Idea" Page Enhancement Request -> https://ideas.microfocus.com/MFI/nov...ea/Detail/1619)
    Attached Files Attached Files
    Last edited by CRAIGDWILSON; 08-Nov-2017 at 03:04 AM.
    --
    Any Opinions, Thoughts, Solutions, or Blog Entries are my own and may or may not be shared by Novell or any Sane Person
    Please Use at your Own Risk.

    Blog - https://forums.novell.com/blog.php/5830-CRAIGDWILSON

    https://ideas.microfocus.com/mfi/novell-zcm

    Want to Turbo charge your apps and put an end to compatability issues?
    https://www.microfocus.com/products/...top-containers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •