Creating and Deleting Users Using API

TestStand 2017 Help

Edition Date: November 2017

Part Number: 370052W-01

»View Product Info

Download Help (Windows Only)
NI TestStand 2014 Help
NI TestStand 2014 SP1 Help
TestStand 2016 Help
TestStand 2016 SP1 Help
TestStand 2017 Help

Purpose

This example demonstrates how to programmatically create and delete users.

Example File Location


Open Example

<TestStand Public>\Examples\TestStand API\Creating & Deleting Users Using API\Creating & Deleting Users Using API.seq

Highlighted Features

Major API

Prerequisites

You must be logged into TestStand as a user with administrator privileges.

How to Use This Example

Complete the following steps to review the sequences and steps in this example.

  1. On the Steps pane of the MainSequence, select the Create or Delete a User step.
  2. On the Step Settings pane, click the Text and Buttons tab. When you run the sequence, you select whether you want to create a user or delete a user. The If and Else steps call the Create User sequence or Delete User sequence, depending on which option you select.
  3. On the Sequences pane, select the Create User sequence, which specifies the following functionality:
    1. The Get New User Name step prompts for a new user name.
    2. The If step uses the Engine.UserNameExists method to determine whether the user name already exists. If the user name does not exist, the user is created.
    3. The Select User Group step in the If structure prompts you to select a group for the user.
    4. A series of Statement steps perform API calls to create the new user and increment the change count of the user file.
  4. On the Steps pane, select each Statement step one at a time and click the Expression edit tab on the Step Settings pane to review the expression each step uses. The steps use the Engine.NewUser method to create the new user, the UsersFile.UserList property and PropertyObject.SetPropertyObjectByOffset method to insert the new user in the user list, and the Engine.GetUserGroup method and PropertyObject.SetValStringByOffset method to add the user to a group.
  5. On the Sequences pane, select the Delete User sequence, which specifies the following functionality:
    1. The Get User Names step, which is a Sequence Call step, calls a subsequence to generate an array of all user names in the user list.
    2. In the If structure, the Delete User sequence verifies that more than one user exists so that you cannot delete the only user and become locked out of TestStand.
    3. The Delete User sequence stores the user name to delete in a local variable before the user is actually deleted and removed from any groups.
    4. A Statement step increments the change count of the user file.
  6. On the Steps pane of the MainSequence, select the Save Users File step.
  7. On the Step Settings pane, click the Text and Buttons tab. When you run the sequence and have selected whether to create a new user or delete a user, the precondition evaluates whether the Users file has been modified. If the file has been modified, the step prompts you to save the changes. If you select No, TestStand reflects the changes in the User Manager but does not save the changes.

Complete the following steps to run the example.

  1. On the Sequences pane, select the MainSequence.
  2. Select Execute»Run MainSequence to run the sequence.
  3. In the Create or Delete a User dialog box, click Create User.
  4. In the New User Name dialog box, enter a name for the new user and click OK.
  5. In the User Group dialog box, select any group for the new user.
  6. In the Save the Modified Users File dialog box, select whether you want to save the changes made to the User file.
  7. Select Execute»Restart to run the sequence again.
  8. In the Create or Delete a User dialog box, click Delete User.
  9. In the Select User dialog box, select the new user you created in step 4.
  10. In the Save the Modified Users File dialog box, select whether you want to save the changes made to the User file.

WAS THIS ARTICLE HELPFUL?

Not Helpful