none
Need Help - Batch File RRS feed

  • Question

  • This Script works well on Clean install but if it has an old version and I want it to check the variable gets broke someone in batch... I can type it in Command line and it works.

    Script:


    The Error I receive is:  Look at the IF Statement or even if I echo it keeps stripping off %2 (first 2 characters)


    • Edited by cfreeman21 Tuesday, August 5, 2014 5:32 PM script no longer needed on post
    Friday, August 1, 2014 9:25 PM

Answers

  • This Script works well on Clean install but if it has an old version and I want it to check the variable gets broke someone in batch.The Error I receive is:  Look at the IF Statement or even if I echo it keeps stripping off %2 (first 2 characters)

    Sorry to say so but this batch file is almost unmaintainable. It lacks structure and its flow is very hard to follow. As Bill suggests, you should not need to do this.

    You can probably fix the current problem by replacing the bad block with the good block (see below). However, there might be additional problems. Note also these points:

    • Variable names must not start with numbers. This goes for most scripting languages.
    • Your "else if" constructs are neither required nor are they valid for batch files.

    Bad block:

    FOR /F "tokens=2 delims==" %%G IN ('WMIC DATAFILE WHERE NAME^="C:\\Program Files (x86)\\20-20 Technologies\\Design\\Bin\\System\\Design.exe" get version /format:value') DO SET 2020VERSION=%%G

    IF %2020VERSION%==%2020CURRENTVERSION% (goto Complete)
    else IF %2020VERSION%==%2020VERSION10_0% (GOTO Uninstall_10.0.4.1049)
    else IF %2020VERSION%==%2020VERSION10_1% (GOTO Uninstall_10.1.1.23)
    else IF %2020VERSION%==%2020VERSION10_2% (GOTO Uninstall_10.2.0.37)
    else IF %2020VERSION%==%2020VERSION10_3% (GOTO Uninstall_10.3.0.31)

    Replace with:

    FOR /F "tokens=2 delims==" %%G IN ('WMIC DATAFILE WHERE NAME^="C:\\Program Files (x86)\\20-20 Technologies\\Design\\Bin\\System\\Design.exe" get version /format:value') DO SET x2020VERSION=%%G

    IF %x2020VERSION%==%2020CURRENTVERSION% goto Complete
    IF %x2020VERSION%==%2020VERSION10_0% goto Uninstall_10.0.4.1049
    IF %x2020VERSION%==%2020VERSION10_1% goto Uninstall_10.1.1.23
    IF %x2020VERSION%==%2020VERSION10_2% goto Uninstall_10.2.0.37
    IF %x2020VERSION%==%2020VERSION10_3% goto Uninstall_10.3.0.31
    goto :eof

    • Proposed as answer by Frederik Long Saturday, August 2, 2014 9:11 PM
    • Edited by Frederik Long Sunday, August 3, 2014 9:38 PM
    • Marked as answer by cfreeman21 Monday, August 4, 2014 12:12 PM
    Friday, August 1, 2014 11:41 PM

All replies

  • I recommend following the vendor's deployment instructions rather than trying to script it yourself.

    If the package is designed correctly, it will automatically uninstall older an older version and then install the current version.


    -- Bill Stewart [Bill_Stewart]

    Friday, August 1, 2014 9:28 PM
    Moderator
  • This Script works well on Clean install but if it has an old version and I want it to check the variable gets broke someone in batch.The Error I receive is:  Look at the IF Statement or even if I echo it keeps stripping off %2 (first 2 characters)

    Sorry to say so but this batch file is almost unmaintainable. It lacks structure and its flow is very hard to follow. As Bill suggests, you should not need to do this.

    You can probably fix the current problem by replacing the bad block with the good block (see below). However, there might be additional problems. Note also these points:

    • Variable names must not start with numbers. This goes for most scripting languages.
    • Your "else if" constructs are neither required nor are they valid for batch files.

    Bad block:

    FOR /F "tokens=2 delims==" %%G IN ('WMIC DATAFILE WHERE NAME^="C:\\Program Files (x86)\\20-20 Technologies\\Design\\Bin\\System\\Design.exe" get version /format:value') DO SET 2020VERSION=%%G

    IF %2020VERSION%==%2020CURRENTVERSION% (goto Complete)
    else IF %2020VERSION%==%2020VERSION10_0% (GOTO Uninstall_10.0.4.1049)
    else IF %2020VERSION%==%2020VERSION10_1% (GOTO Uninstall_10.1.1.23)
    else IF %2020VERSION%==%2020VERSION10_2% (GOTO Uninstall_10.2.0.37)
    else IF %2020VERSION%==%2020VERSION10_3% (GOTO Uninstall_10.3.0.31)

    Replace with:

    FOR /F "tokens=2 delims==" %%G IN ('WMIC DATAFILE WHERE NAME^="C:\\Program Files (x86)\\20-20 Technologies\\Design\\Bin\\System\\Design.exe" get version /format:value') DO SET x2020VERSION=%%G

    IF %x2020VERSION%==%2020CURRENTVERSION% goto Complete
    IF %x2020VERSION%==%2020VERSION10_0% goto Uninstall_10.0.4.1049
    IF %x2020VERSION%==%2020VERSION10_1% goto Uninstall_10.1.1.23
    IF %x2020VERSION%==%2020VERSION10_2% goto Uninstall_10.2.0.37
    IF %x2020VERSION%==%2020VERSION10_3% goto Uninstall_10.3.0.31
    goto :eof

    • Proposed as answer by Frederik Long Saturday, August 2, 2014 9:11 PM
    • Edited by Frederik Long Sunday, August 3, 2014 9:38 PM
    • Marked as answer by cfreeman21 Monday, August 4, 2014 12:12 PM
    Friday, August 1, 2014 11:41 PM
  • Unfortunately this manufacture does not right in a Uninstall for there product, BUT it is requried to uninstall to upgrade the application...  Frederick I updated the scripts make my number variables with x as recommended and the script is now working... Thanks!
    Monday, August 4, 2014 12:12 PM