You can create a new user in NI TestStand by using the NI TestStand API. This can be done using the Engine
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.
- Use the NewUser method of the Engine class and pass a null reference to get a reference to a new User object:
Engine.UsersFile.UserList.SetPropertyObjectByOffset(Engine.UsersFile.UserList.GetNumElements(), PropOption_InsertIfMissing, Engine.NewUser(null).AsPropertyObject())
- 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:
- Increment the UsersFile change count to mark it as being modified:
- Save the UsersFile to ensure the new User is stored to the UsersFile on disk:
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.