Set user dependant installer variable

Answered

Comments

2 comments

  • Avatar
    wojciechka

    The <if> action can be used to set a value based on ${system_username} variable:

    <if>
        <actionList>
            <!-- if ${system_username} equals X, set to predefined value -->
            <setInstallerVariable>
                <name>variable_name</name>
                <value>value</value>
            </setInstallerVariable>
        </actionList>
        <elseActionList>
            <!-- if ${system_username} does not equal X, set to other value -->
            <setInstallerVariable>
                <name>variable_name</name>
                <value>${system_username}</value>
            </setInstallerVariable>
        </elseActionList>
        <conditionRuleList>
            <compareValues>
                <logic>equals</logic>
                <value1>${system_username}</value1>
                <value2>X</value2>
            </compareValues>
        </conditionRuleList>
    </if>
    

    The action is described in more details in the If / Else section of InstallBuilder User Guide.

  • Avatar
    wojciechka

    We will investigate making the ${system_username} variable available at build time. As a workaround you can set it manually by doing:

    <setInstallerVariable>
        <name>system_username</name>
        <value>${env(USERNAME)}</value>
        <ruleList>
            <compareTextLength>
                <length>0</length>
                <logic>greater</logic>
                <text>${env(USERNAME)}</text>
            </compareTextLength>
        </ruleList>
    </setInstallerVariable>
    <setInstallerVariable>
        <name>system_username</name>
        <value>${env(LOGNAME)}</value>
        <ruleList>
            <compareTextLength>
                <length>0</length>
                <logic>greater</logic>
                <text>${env(LOGNAME)}</text>
            </compareTextLength>
        </ruleList>
    </setInstallerVariable>
    <setInstallerVariable>
        <name>system_username</name>
        <value>${env(USER)}</value>
        <ruleList>
            <compareTextLength>
                <length>0</length>
                <logic>greater</logic>
                <text>${env(USER)}</text>
            </compareTextLength>
        </ruleList>
    </setInstallerVariable>
    

    This will use USERNAME, LOGNAME and USER environment variables to get the user name, in that order.

Please sign in to leave a comment.