MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Get Name/Directory of the Batch File[Next]: Logging RollOver (keep
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Batch Files->Batch File Tips and Tricks->Indirect Access to Environment Variables (by reference)

Indirect Access to Environment Variables (by reference)

You may wish to indirectly read/write to an environment variable whose name is (or can be) contained by another environment variable.

You will almost always want to do this inside a subroutine so that is what this code shows:

@echo off
setlocal ENABLEDELAYEDEXPANSION

set COUNTER=11
call :ADD1 "COUNTER"

echo TEST: COUNTERS new value is "%COUNTER%" (should be "12")
goto :EOF


@rem ### Manipulate value where only variable's name is passed #########
:Add1
    @rem *** Get Passed variable name and its value ***
    set  VarName=%~1
    set VarValue=!%VarName%!
    echo TEST: VARNAME "%VarName%" has a value of "%VarValue%"

    @rem *** Change the value (we will return it) ***
    set /a VarValue=VarValue + 1

    @rem *** "Return" the value ***
    set %VarName%=%VarValue%
    goto :EOF


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Get Name/Directory of the Batch File[Next]: Logging RollOver (keep


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday May 28 2022 at 3:11pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.