Prevent LabVIEW Executable to Run by Different Windows Users

Updated Nov 2, 2023

Environment

Software

  • LabVIEW 2020 SP1

You have an application made in LabVIEW, which should not have multiple instances running.
Adding the property allowmultipleinstances = TRUE works on the same Windows User, but it won't work if the application is executed from different Users on the same Computer.

There are several approaches with different caveats to fulfil this requirement. In this article we will use an approach that checks if the application is already running on Windows before executing it. In the Next Steps section you will find another approaches for this purpose.

The example has been made in LabVIEW 2020 SP1 (32 bits) and tested on Windows 10 (64 bits).

After you developed and built your main application, you will develop and build a Launcher. This Launcher will check if your main application is already running, if it's not, the Launcher will execute your application. If your main application is already running, the Launcher will give you a message, showing that the main application has been already executed and it is still running. After clicking OK on the message, the Launcher application will exit.
  1. Create your main program code. For example, we will use a program that generates a random value from a specified range.
MainVISnippet.png
Main application example. Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
  1. Build an Application (EXE) from your Code.  When you create it, the Target filename will be the name of the process that you will look for later.
BuildProperties.JPG
 
  1. After you build your application, create the Launcher that will look for the process of your application on Windows before launching it. Use the Target Filename string constant to look for your Main application Filename and the Path of the Application string constant to run it, in case it is not already running.
LauncherSnippet.png
Launcher application Example. Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
  1. Build an Application (EXE) of the Launcher.
  2. Run your Main application through the Launcher application.
IMPORTANT: Make sure that you always execute your application from the Launcher and not from the Main program executable.

If your Main application is not running, the Launcher will execute it. You will not see the Launcher's front panel, as it will exit the execution after finishing the opening of the Main program.
MyMain.JPG

If your Main application is already running, the Launcher will show you an error message, showing that the Main program is already running. After pressing the OK Button, the Launcher will close.
AlreadyRunning.JPG

Next Steps

  1. Other approaches to prevent running the executable by different Windows users:
  • Create a variable that all users can access. Set the value to True each time an application is running and back to False on termination/failure. Modify the app to always check this variable before executing the main code. Disadvantage: If a safe shutdown is not observed (abort code or power failure), the variable must be reset manually.
  • Make an intentional Mutex: the application accesses an element (use a file, as an example) and claims the resource. The next instance of the app tries to access the resource as well, but the first instance still blocks it, forcing the second instance to just wait. Instance two would then time out, which you can handle with a pop-up dialog box or something that says the code is already running.
  • Use a non-reentrant VI with a first call and a Feedback Node to return one GUID or UUID per instance. This has a non-zero chance of duplicating based on the GUID algorithm.
  • Pass an ID as a command line parameter. That means you need a caller to start those who are "non-reentrant" and can use something like the current time for high resolution or a running counter stored in a file to assign the IDs.
  1. Improve the error handling in the Launcher application to behave as your needs.