Check for running processes

Last modified by Jannis Klein on 2024/08/13 08:19

Initial situation

Sometimes it is unavoidable that you have to update software or programs that affect all or some of the Clients in your organisation, even during normal working hours. In this case, it is useful to be able to check, for example, whether a particular program is currently being actively used or not, in order to get an overview of how quickly certain updates can be deployed.

This Client Command is needed for software distribution, for example. It checks whether a particular process belonging to a programme that is to be updated is still running. The user can be informed that the program and the associated process should be closed in order to perform such an update. It does not matter whether you are checking Microsoft Word or an Internet browser. In what follows, the Command is designed to be generic, so that you can quickly adapt it specifically for other programs. For this reason, the following use case uses variables (system variables) that require very little customisation and make certain components of the script more flexible and variable.

This use case shows how you can specifically check on the clients whether a particular program or process is running. Mozilla Firefox is used as an example. You will also gain an insight into how to use variables universally.

Checking for running programs and processes

Select a Script

  1. Navigate to the Client Commands > Create module.
  2. Click Add on the ribbon bar. The Client Command Editor will open and you will need to decide whether it is a Console or Client Script. In this case select Client Script.

Setting and editing a Command Set project variable

  1. First select the Variables > Set Project Variable Command from the Command List.
  2. Double click on the Command and select the General tab.
  3. Enter a name under the description of the action. In this example, "Set project variable SOFTWARE_NAME to 'Mozilla Firefox'" is inserted.
  4. Switch to the Details tab.
  5. Under the variable settings, click on the icon next to the variable name.
  6. Optional: Create a new variable under Actions. Name it "SOFTWARE_NAME" and click on the plus icon. Then click the OK button to complete the step.

Hinweis  Note:  

This step is optional if you have not already created the variable.

       7. Enter the name of the software in the One line text box. In this example it is „Mozilla Firefox“.
       8. Click OK.

65_Use Case Client Command_Auf laufende Prozesse Variableneinstellungen vornehmen.png

Making variable settings

Set and edit Command Set project variable

  1. Select the Set project variable Command again.
  2. Double click the Command and open the General tab.
  3. Enter the name in the description field, e.g. Set project variable SOFTWARE_EXE to „firefox.exe“.
  4. Switch to the Details tab.
  5. Optional: Create a new variable under Actions. Name it "SOFTWARE_EXE" and click the plus icon. Click OK to complete this step.

Hinweis  Note:  

This step is optional if you have not already created the variable.

      6. Enter the process name in the Single line text box.

Hinweis  Note:  

You can query the name of the process using Task Manager by opening the running processes and displaying the name on the Details tab.

          Enter the text „firefox.exe“.
      7. Click OK.

65_Use Case Client Commands_Auf laufende Prozesse überprüfen_Variableneinstellungen vornehmen.png

Setting variables

Warning  Warning:  

With the two Set project variable Commands you have entered two values that you need to check a specific process. In this case you have entered the name of the software (Mozilla Firefox) and the name of the executable file (firefox.exe). If, at a later date, you want to check the whole Command for a different program, you only need to change the first two lines.

Insert and customise Get process ID Command

This Command allows you to determine the current process ID of the running process or program. This makes it possible to check, in the ongoing structure of the application example, whether the particular process or program is actively running on a Client or not.

  1. Select the Process and Shell > Get Process ID Command.
  2. Double click to open the Command.
  3. Under Process / Target variable, enable the ... with process option by clicking the button.
  4. Insert the appropriate variable (%SOFTWARE_EXE%). This variable is used to check that Mozilla Firefox is running.

Warning  Warning:  

To avoid typing errors, we recommend that you do not enter the variables manually. Instead, either insert them using the icon in the ... with process line, or press the CTRL + Spacebar combination in the field. This will open the list of variables and you can select the appropriate one.

Hinweis  Note:  

The firefox.exe is not explicitly entered here in order to make the Client Commands as variable as possible for other checks.  This will allow you to easily change the entries from line 1 and line 2 after the Command is complete and check for other processes by entering a different program there.

     5. Under Save results in, click on the icon to the right of the variable name.
     6. Open Project Variables from the drop down menu at the top.
     7. Enter the name "CHECK_EXE" under the actions and click on the plus icon.
         Click OK to complete this step.

65_Use Case Client Commands_Variable auswählen.png

Select variable

Hinweis  Note:  

You are free to choose any variable name. However, it is recommended that you choose names that are appropriate to the topic so that you can understand exactly what a variable does later in the process.

       8. The result will be stored in the CHECK_EXE variable.
       9. Then click OK.

65_Use Case Client Commands_Auf laufende Prozesse überprüfen Get process ID_484.png

Get process ID

You have now added your first Commands to the Client Script. At this point you can check on your computer to see if the Command works. To do this, click the Start button on the quick selection bar or press the F9 key combination. This will run the first three Commands.

Now open the Run Log in the lower pane where all the logs of the Client Script are stored. Depending on whether you have the Mozilla Firefox browser open or not, you will see a different value. This is explained by the variable name "CHECK_EXE". If the variable is 0, the programme is not open. If the variable is >0, the program is open and running in the background. In the graphic shown here, the variable is set to 0, so the program is not open. 

Warning  Warning:  

If the process ID is not running (and therefore 0), the Client Script will encounter an error (see graphic). You should ignore this error by checking the box next to it. This ensures that the 0 is also a valid result in the script and that the Client Command can continue to run. You will then need to check that the value is 0 or greater than 0.

65_Use Case_Client Commands_Auf laufende Prozesse überprüfen_Durchlauf des CCs_1275.png

Running the client commands to check for running processes

Command If ... Then insert and customise

  1. In the Command List, select the Flow Control > If ... Command.
  2. Double click on the Command to open it and switch to the General tab.
  3. Under Action description, enter a name that describes the Command. In this example, "If (%CHECK_EXE% <> 0) Then - If the process is running ..." is written so that it is clear in the main field which condition is to be fulfilled here.
  4. Switch to the Details tab.
  5. Insert the values to be checked under the conditions. In value 1, the variable %CHECK_EXE% must be entered as this is what is to be checked. The variable in value 1 will then be filled when the programme is executed.
  6. Select the unequal operator (< >) to check whether the programme or process is running or not. This operator is particularly suitable because the value can always be different and you can therefore include all possibilities.
  7. Insert the number 0 as value 2. This is the value used as the condition for the operator.
  8. Click OK to complete the Command.

65_Use Case Client Commands_Variable auswählen.png

If ... Then Command

If the process is running, the row is completed as the condition is met. If the process is not running, the line is skipped.

Optional: Set and edit Command Dialogs

You can set this Command as optional if you want your Clients to see a dialogue box informing them that the program should be closed. The message can be customised. Note that the Command must be nested under the previous command (If (%CHECK_EXE% <> 0) Then) for it to work correctly.

  1. Select the Dialogs > Dialogs Command from the Command List.
  2. Open the Command by double clicking on it and open the Message Settings tab.
  3. Enter a suitable title for the message. Again, we recommend that you use the project variables and not the name of the program to keep the whole module variable. For example, you could write Software Update: %SOFTWARE_NAME%.
  4. Insert the message for the Clients to be displayed when the program is still open.

Hinweis  Note:  

If you want to use a project variable to use the name of the user in the address, you can use the %LOGGEDONUSER_NAME% variable.

This will use the logged-in user name as the salutation.

        Optional: Change the message type and/or available buttons and custom captions.

Hinweis  Note:  

If you want to see the message text before completing the command, you can do this by clicking the Preview button.

       5. Click OK.

65_Use Case Client Commands_Auf laufende Prozesse überprüfen Dialog eingeben.png

Enter a dialog

Inserting and customising the Else Command

The Else block belongs to the previous If ... Then Command. Make sure that the Command is inserted at the same level so that the conditions between If ... Then and Else are completed.

  1. Navigate back to the Command List and select the Flow Control > Else Command.

Hinweis  Note:  

Indent this Command, either using the quick selection bar or the shortcut CTRL + left arrow key, so that it appears on the same level as If ... Then Command.

      2. Open the Command by double clicking it.
      3. Optional: Add a comment in case the Else block should be executed.
      4. Click OK.

65_Use Case Client Commands_Auf laufende Prozesse überprüfen_Else_476.png

Else Command

Inserting and editing an Exit script Command

  1. Select Flow Control > Exit script from the Command List.
  2. Insert the block below the Else Command so that it is indented.
  3. Double click on the Command to open it.
  4. Select the OK condition in the Details tab. This will mark the script as successful.

Hinweis  Note:  

If the script fails at this point, you will need to select Error from the drop down menu.

     5. Enter a reason why the Client Commands were successful.
     6. Click OK to close the Command.

65_Use Case Client Commands_Auf laufende Prozesse überprüfen_Skript beenden_484.png

Exit Script

Your Client Script should now consist of a total of seven blocks. Save the Client Command.

65_Use Case Client Commands_Auf laufende Prozesse überprüfen.png

Client Command Editor: Checking for running processes

Running the Client Command through the phases

Finally, the client command must be run through the Test, Synchronise, Release and Execute phases before it can be used. This is the only way to check whether a particular program or process is actively running on a Client.

© Aagon GmbH 2024
Besuchen Sie unsere neue Aagon-Community