From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Retrieve Windows User Name Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview

Call Windows API by using LabVIEW call library function node

 

Description

This example program demonstrates how we can use LabVIEW and the call library function node to call into the Windows API.  In specific, we are using the advapi32.dll and the function GetUserNameA to retrieve the currently logged in user name.

 

Requirements

Software

LabVIEW 2013 (or compatible)

 

Steps to Implement or Execute Code

  1. This code will function by itself at either top level or as a subVI. 

 

Additional Information or Reference

Note that the string here is simply initialized to a static length. If the user name is longer, simply make the string constant larger. The maximum user name length for Windows is 256 characters.

1-393BD.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Cole R.
National Instruments
Software Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.