How To Give a LabVIEW Thread Elevated User Access

Updated Oct 25, 2023

Environment

Software

  • LabVIEW

I am working on an application that requires user rights elevation to execute commands in the operating system. This needs to happen in parallel while the rest of the application uses a standard limited access user privilege. How do I achieve this?

There are several ways to achieve a unique thread that can be elevated. Placing code in a unique thread would allow the ability to spawn code, elevate, perform action and then de-spawn code and thread.
  • Timed structures spawn a unique thread per structure. 
  • The only single thread execution system is the UI thread. If your elevated VIs were all ran in the UI execution system, you could have one thread run all the code.
    • This is not recommended, as this has the issue of running code in the UI thread, where various events are also ran in this thread and can pause execution if not handled correctly. 
  • You can run "subroutine" VIs, where all the code in that VI would run in a single thread. 
    • This comes with a caveat that Asynchronous operations aren't allowed in subroutines. This will depend on why your application needs elevation. 
After creating a unique thread, you can use Operating System functions to give the thread elevated access. For Windows, this can be performed using the Win32 API LogonUserA function to log in as a user with elevated privileges.

This will allow the thread that calls the LogonUserA function to run with elevated privileges while the rest of the application runs at a standard privilege level.