This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Build a File Path to a Username Dependent Directory

Updated Aug 21, 2023

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full

Issue Details

  • I am trying to build a path to a directory on my computer that is dependent on the Windows username.  I want this code to work on any computer, regardless of the username.  Is there a tool for this?
  • Is there a way to programmatically get the Windows user name from LabVIEW? I would like to build a path constant specific to the currently logged-on user.  For example, I would like to create files on the user's desktop, and the path to the desktop contains the Windows user name.

Solution

There are different methods you can do to achieve this, try one of the following:
  • The "Get System Directory VI" can return the file path for many username dependent directories.  After placing the function, you can select the directory via the enum input.  The function will then return a file path.
  • You can obtain the Windows user name in LabVIEW using the System Exec VI. Use the command echo %username% with the System Exec VI to programmatically obtain the Windows user name in LabVIEW.  This value can then be used with the "build path" function, to create your file path.
 

Figure 1 System Exec VI
  • You also can obtain the Windows user name using the Application:User Name property. After you add the Property Node to the block diagram, right-click Property and select Select Property»Application»User Name.  This value can then be used with the "build path" function, to create your file path.
 

Figure 2 User Name Property Node
The User Name property returns the Operating System user name from Revision History. If you changed the default user name settings of Revision History, the User Name property might not return the correct user name. Use the System Exec function instead. Both techniques result in the same string.
 

Figure 3 User Name Output

Additional Information

A full list of Windows Environment Variables may be obtained by typing set at the command prompt. To return any of the Environment Variables, use the command echo %EnvironmentVariableName%.