How to terminate my application?

Answered

Comments

1 comment

  • Avatar
    wojciechka

    You can use built-in actions and rules to implement checking that process exists and waiting for it to exit. You can either bundle an application that sends an appropriate message (i.e. using SendMessage() API) or use the built-in <kill> action.

    The example with shipping an application to quit is as follows:

    <readyToInstallActionList>
      <if>
        <actionList>
          <unpackFile>
            <component>tools</component>
            <destination>${system_temp_directory}/myapp-askquit.exe</destination>
            <folder>tools</folder>
            <origin>myapp-askquit.exe</origin>
          </unpackFile>
          <showProgressDialog>
            <title>Requesting myapp to exit</title>
            <actionList>
              <while>
                <actionList>
                  <runProgram>
                    <program>${system_temp_directory}/myapp-askquit.exe</program>
                    <programArguments></programArguments>
                  </runProgram>
                  <wait>
                    <ms>5000</ms>
                  </wait>
                </actionList>
                <ruleList>
                  <processTest>
                    <logic>is_running</logic>
                    <name>myapp.exe</name>
                  </processTest>
                </ruleList>
              </while>
            </actionList>
          </showProgressDialog>
          <deleteFile>
            <path>${system_temp_directory}/myapp-askquit.exe</path>
          </deleteFile>
        </actionList>
        <conditionRuleList>
          <processTest>
            <logic>is_running</logic>
            <name>myapp.exe</name>
          </processTest>
        </conditionRuleList>
      </if>
    </readyToInstallActionList>
    

    This checks that myapp.exe is running, if it is, it asks the application to exit and waits for it to exit. It also shows a progress dialog so user is aware what is happening.

    It keeps sending the quit message until the process exits. It can be moved to before the <while> action so that sending the message is only done once.

    As for using the <kill> action, you can simply replace <runProgram> with:

    <kill>
      <name>myapp.exe</name>
    </kill>
    

    This will terminate the application, however, it will prevent asking user to perform certain actions - i.e. ask if it should write unsaved data.

Please sign in to leave a comment.