How to distinguish installer and installed software using "processTest" rule?

Answered

Comments

1 comment

  • Avatar
    Dirk Stegemann

    For what it's worth, I implemented a new <ruleDefinition> that is able to check on OS X, whether a certain program is running, identified by its path (or path segment).

    Feel free to re-use it.

    Currently, the implementation runs the ps command line tool, then runs a <compareText> rule to check for a hard-coded path. Please adjust appropriately.


    <ruleDefinition>
      <!--
          function:       isSoftwareRunning()
          parameter:      none
          Description:    Evaluates whether the application is running.
      -->
      <name>isSoftwareRunning</name>
    
      <parameterList>
          <!-- This function takes no parameters -->
      </parameterList>
    
      <actionList>
    
        <actionGroup>
          <!-- Rule actions performed on Windows -->
          <actionList>
            <if>
              <conditionRuleList>
                <ruleGroup>
                  <ruleEvaluationLogic>or</ruleEvaluationLogic>
                  <ruleList>
                    <processTest logic="is_running" 
                                 name="My Cool Software.exe" />
                    <windowsServiceTest condition="is_running" 
                                        service="My Cool Software.exe" />
                  </ruleList>
                </ruleGroup>
              </conditionRuleList>
    
              <actionList>
                <setInstallerVariable name="program_is_running" 
                                      value="true" />
              </actionList>
    
              <elseActionList>
                <setInstallerVariable name="program_is_running" 
                                      value="false" />
              </elseActionList>
            </if>
          </actionList>
    
          <ruleList>
              <platformTest type="windows" />
          </ruleList>
        </actionGroup>
    
        <actionGroup>
          <!-- Rule actions performed on OS X -->
          <actionList>
            <setInstallerVariableFromScriptOutput>
              <name>script_output_variable</name>
              <exec>ps</exec>
              <execArgs>-ax</execArgs>
    
              <!-- Error handling -->
              <abortOnError>0</abortOnError>
              <showMessageOnError>0</showMessageOnError>
              <onErrorActionList>
                <logMessage text="ERROR: script command failed" />
    
                <!-- In case of error, pretend the program is NOT running -->
                <setInstallerVariable name="program_is_running" 
                                      value="false" />
              </onErrorActionList>
            </setInstallerVariableFromScriptOutput>
    
            <if>
              <conditionRuleList>
                <compareText>
                  <text>${script_output_variable}</text>
                  <logic>contains</logic>
                  <value>/Applications/My Cool Software.app/Contents/MacOS/My Cool Software</value>
                </compareText>
              </conditionRuleList>
    
              <actionList>
                <setInstallerVariable name="program_is_running" 
                                      value="true" />
              </actionList>
    
              <elseActionList>
                  <setInstallerVariable name="program_is_running" 
                                        value="false" />
              </elseActionList>
            </if>
          </actionList>
    
          <ruleList>
              <platformTest type="osx" />
          </ruleList>
        </actionGroup>
    
        <logMessage text="INFO: ${platform_name}" />
        <logMessage text="INFO: Program is running: ${program_is_running}" />
    
      </actionList>
    
      <ruleList>
          <isTrue value="${program_is_running}" />
      </ruleList>
    
    </ruleDefinition>
    

    To provide a dialog that prevents the installation until the software in question has been closed, we're using the following action:

    <actionDefinition>
      <!--
        function:       showErrorAndExitIfSoftwareIsInUse()
    
        parameter:      none
    
        Description:    Check whether the software is currently being used, 
                        which would prevent us from overwriting it. 
                        If it is, display an appropriate error message and 
                        exit the installer with an appropriate error code. 
      -->
      <name>showErrorAndExitIfSoftwareIsInUse</name>
    
      <parameterList>
          <!-- This function takes no parameters -->
      </parameterList>
    
      <actionList>
        <logMessage text="ENTER showErrorAndExitIfSoftwareIsInUse()" />
    
        <validatedActionGroup showMessageOnError="0" type="abortRetry">
          <severity>warning</severity>
          <text>${msg(StartupCheck.SoftwareInUse.Dialog.Text)}</text>
    
          <actionList>
            <throwError>
              <ruleList>
                <isSoftwareRunning />
              </ruleList>
    
            </throwError>
          </actionList>
    
          <onErrorActionList>
            <logMessage text="WARNING: Software is in use." />
    
            <exitWithExitCode exitCode="1" />
          </onErrorActionList>
        </validatedActionGroup>
    
        <logMessage text="EXIT showErrorAndExitIfSoftwareIsInUse()" />
      </actionList>
    
    </actionDefinition>
    

Please sign in to leave a comment.