10-26-2023 10:41 AM
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.
Solved! Go to Solution.
10-26-2023 01:31 PM
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
10-31-2023 09:09 AM
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.