NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

how do i create a new user in visual basic

hello all!
I'm customizing TS Operator Interface and I'm trying to add a new user with VB code.
is anyone has any idea how to do this?

Advanced thanks,Avi.
0 Kudos
Message 1 of 3
(3,417 Views)
Avi,

There is an example that ships with TS 2.0 called CreateDeleteUsers.seq.

While this example does NOT use VB, the ActiveX calls it uses are the same that you need to use in VB. Specifically you will want to look at the Creat User sequence in this sequence file.

I did notice one unecessary step in that sequence that probably adds a lot of overhead to the example. The second step in the sequence, UserProfile, creates a new instance of the TestStand engine. This is uncessary since the step could have used the existing instance of the engine that is stored in RunState.Engine.

The new user created in this example has the priveleges of the Adminstrator profile. You will need to make modifications to create users with different profiles.

Another option for creating
new users is to call them method Engine.DisplayNewUserDialog. This displays a dialog with which an operator can create a new user. This option requires user input while the example above can be made to execute entirely programmatically without user input.
0 Kudos
Message 2 of 3
(3,417 Views)
Hello Avi,

Looks like the TSengine doesn't handle the save and update operations when invoking 'NewUser' method, so you have to handle these by your own. The following code (which is the menu callback for creating a new user in an Operator interface) might give you an answer for your question:


Private Sub NewUser_Click()
Dim objNewUser As User
Dim tmpUser As User
Dim users As PropertyObject
Dim OkCancel As Boolean
Dim loginName As String
Dim usersFilePath As String
Const USERS_FILE_NAME As String = "\users.ini"
Const USER_LISTS As String = "UserLists.Users" 'section of file containing user lists

'Check if the current user has 'EditUsers' privileges
If Data.TestEngine.CurrentUserHasPrivilege(Priv_EditUsers) Then
OkCancel = Data.TestEngine.DisplayNewUserDialog("New User", True, objNewUser)
If OkCancel Then
'Get user login name
loginName = objNewUser.loginName
'Get users file path
usersFilePath = Data.TestEngine.ConfigDirectory
usersFilePath = usersFilePath + USERS_FILE_NAME
'Create new object for all users
Set users = Data.TestEngine.NewPropertyObject(PropValType_Container, False, "", 0)
'Read all users from users.ini
Call users.Read(usersFilePath, USER_LISTS, 0)
'Check if user name already exist
If Not Data.TestEngine.UserNameExists(loginName) Then
'Insert new user into user object
Call users.SetPropertyObject(loginName, PropOption_InsertIfMissing, objNewUser)
'Write user object back to users.ini
Call users.Write(usersFilePath, USER_LISTS, 0)
End If
End If
End If

End Sub

After executing the code above you'll have to restart the operator interface in order to see the newly created user in the 'TSEngine.DisplayLoginDialog' (seems to be a bug here).

Hope this solved your problem and
feel free for further questions

Regards,
Silvius
Silvius Iancu
0 Kudos
Message 3 of 3
(3,417 Views)