NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand API Get a List of all Possible User Privileges

Solved!
Go to solution

I'm able to read all possible user groups including custom ones, but I can't find a way to read the all privilege names using the API. Is there a way to accomplish this? I want to do this so I can check the current user's privileges using User.HasPrivilege. I can't do that if I don't have the name of the privilege to check for and I want to be able to handle custom privileges without having to hard code them.

0 Kudos
Message 1 of 3
(1,410 Views)

This can be done.

Privileges are nothing more than an array of PropertyObject, so iterate over the array to examine/read each item.

In this example, each privilege is sent to the debug window (this assumes that you have the User object)

 

 PropertyObject[] propertySubObjects = user.Privileges.GetSubProperties("", 0);
            foreach (PropertyObject propertyObject in propertySubObjects)
            {

                value = string.Empty;
                if (propertyObject.Type.DisplayString == "Boolean")
                {
                    value = propertyObject.GetValBoolean("", 0).ToString();
                }

                System.Diagnostics.Debug.WriteLine($"{propertyObject.Name}, {propertyObject.Type.DisplayString}, {value}");

                // child of privileges might be a container, so iterate container
                foreach (PropertyObject childObject in propertyObject.GetSubProperties("", 0))
                {
                    value = string.Empty;
                    if (childObject.Type.DisplayString == "Boolean")
                    {
                        value = childObject.GetValBoolean("", 0).ToString();
                    }
                    System.Diagnostics.Debug.WriteLine($"{childObject.Name}, {childObject.Type.DisplayString}, {value}".PadLeft(40));
                }
            }

 

The output of the above code example looks like this:

GrantAll, Boolean, False
Custom, NI_UserCustomPrivileges (Container), 
                GrantAll, Boolean, False
Operate, Container, 
                 GrantAll, Boolean, True
                 Execute, Boolean, False
               Terminate, Boolean, False
                   Abort, Boolean, False
Debug, Container, 
                GrantAll, Boolean, False
         ControlExecFlow, Boolean, False
               SinglePass, Boolean, True
          RunAnySequence, Boolean, False
        RunSelectedTests, Boolean, False
        LoopSelectedTests, Boolean, True
      EditStationGlobals, Boolean, False
    EditRuntimeVariables, Boolean, False
Develop, Container, 
                GrantAll, Boolean, False
       EditSequenceFiles, Boolean, False
       SaveSequenceFiles, Boolean, False
           EditWorkspace, Boolean, False
        UseSourceControl, Boolean, False
Configure, Container, 
                GrantAll, Boolean, False
           EditTemplates, Boolean, False
               EditTypes, Boolean, False
            ConfigEngine, Boolean, False
           ConfigAdapter, Boolean, False
               ConfigApp, Boolean, False
            ConfigReport, Boolean, False
          ConfigDatabase, Boolean, False
             ConfigModel, Boolean, False
               EditUsers, Boolean, False
   EditProcessModelFiles, Boolean, False

 

Message 2 of 3
(1,398 Views)
Solution
Accepted by topic author al_g

Using your suggestions I was able to ferret out the custom privileges using LabVIEW as shown below. One thing to note, this PropertyObject is a Structure/Cluster not an array. This requires different methods than array objects.

 

 

   

al_g_1-1698761324453.png

 

0 Kudos
Message 3 of 3
(1,358 Views)