Getting the Windows User Name in LabVIEW

Updated Jan 28, 2026

Reported In

Software

  • LabVIEW

Operating System

  • Windows

Issue Details

How to get the current logged-in Windows username in LabVIEW?

Solution

There are three methods could be used to retrieve Windows username in LabVIEW.

Method 1

If you only need the Windows username, then the following instruction will suffice:

  1. In the block diagram, place a VI Server Reference.
  2. Click the VI Server Reference, then select This Application.
  3. Connect the output reference to a property node.


  4. Click the property node to select Application>>User Name
  5. Connect a string indicator to the property's output to display the user name.
    option1.png
    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.

Method 2

If you would like to include the domain along with the Windows username in the resulting string, then the following instruction will be best:

  1. Insert an Invoke Node (.NET) into the block diagram
  2. Right-click the invoke node and select Select Class>>.NET Framework>>Browse
  3. In the Select Object from Assembly window, select mscorlib from the Assembly drop-down menu
  4. Scroll down the Objects list and double-click the System.Security.Principal to expand it
  5. Select WindowsIdentity and click OK


  6. Right-click the invoke node and select Select Method>>[S]GetCurrent()
  7. Connect a property node to the reference output of the GetCurrent method
  8. Right-click the property node and select Select Property>>Name
  9. Connect a string indicator to the property's output to display the user name with domain information
    option2.png
    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.

Method 3

It is possible to use System Exec.vi to obtain the username with the domain information

  1. Place a System Exec.vi in the block diagram
  2. Insert whoami command into the its command line input.
  3. Connect a string indicator to the property's standard output of the VI to display the user name with domain information
    option3.png
    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.