Adding a New User in NI TestStand User Management via API

Updated May 7, 2023



  • TestStand

I want to add a new user to NI TestStand user management programmatically through the UI. How could I do this? 

You can create a new user in NI TestStand by using the NI TestStand API. This can be done using the Engine object.
There are three ways to access the Engine object depending on the use-case:
  • Outside of NI TestStand (e.g Custom User Interface): Create or use the Engine object generated by the code (e.g. Get Property from Application Manager)
  • In a sequence within NI TestStand: Use RunState.Engine
  • From a code module called from a sequence: Pass the SequenceContext into the code module and get the Engine via SequenceContext.Engine property or simply pass the Engine into the code module directly via RunState.Engine
Once you have a reference to the Engine, follow the steps below to create a new User object and add it to the list of Users.
  1. Use the NewUser method of the Engine class and pass a null reference to get a reference to a new User object:
  1. Use the SetPropertyObjectByOffset method of the UserList (PropertyObject) class and pass the size of the UserList array as the arrayOffset parameter, the PropOption_InsertIfMissing as the options parameter, and the PropertyObject reference of the User object from step 1 as the newValue parameter to add the new User to the list of TestStand Users:
Engine.UsersFile.UserList.SetPropertyObjectByOffset(Engine.UsersFile.UserList.GetNumElements(), PropOption_InsertIfMissing, Engine.NewUser(null).AsPropertyObject())
  1. Increment the UsersFile change count to mark it as being modified:
  1. Save the UsersFile to ensure the new User is stored to the UsersFile on disk:

Additional Information

Important note: The steps listed above will only create a User and add it to the list of Users. You will still need to give the User privileges or add the User to a User group if you so choose. NI TestStand also ships with an example that may be helpful located in <TestStand Examples>\TestStand API\Creating & Deleting Users Using API.

If you are going to copy the API commands in the steps listed above, you do not need to copy the user object creation described in step 1. This part is implicitly included in the command listed in step 2.