1

I am using "Win32_NetworkLoginProfile " class to extract the user information on my local system. when I have executed "Get-WmiObject -class Win32_NetworkLoginProfile | Select * " in my machine's Powershell, I am getting Flags = 513. I have checked the MSDN link (https://msdn.microsoft.com/en-us/library/aa394221%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396) for the details of this class. I am having a query here:

Flags = 513 is not matching any value in BitValues of Flags. How can I know what 513 stands for?

Thanks.

Leo
  • 315
  • 1
  • 3
  • 17

2 Answers2

1

Flags = 513 in binary format is 10 0000 0001, so you can see that zero and ninth bits are on, according to the link the map is as follows:

bit 0 = Script
bit 1 = Account Disabled
bit 3 = Home Dir Required
bit 4 = Lockout
bit 5 = Password Not Required
bit 6 = Paswword Can't Change
bit 7 = Encrypted Test Password Allowed
bit 8 = Temp Duplicate Account
bit 9 = Normal Account
bit 11 = InterDomain Trust Account
bit 12 = WorkStation Trust Account
bit 13 = Server Trust Account
bit 16 = Don't Expire Password
bit 17 = MNS Logon Account
bit 18 = Smartcard Required
bit 19 = Trusted For Delegation
bit 20 = Not Delegated
bit 21 = Use DES Key Only
bit 22 = Don't Require Preauthorization
bit 23 = Password Expired

And finally 513 corresponds Script (A logon script executed. This value must be set for LAN Manager 2.0 and Windows NT/Windows 2000) and Normal Account (Default account type that represents a typical user).

BTW you can retrieve the map from property qualifiers, take a look here.

You may follow these steps to implement a function, returning values from the map according to incoming number. Assuming that a dictionary containing bit numbers as keys and corresponding values already created. WMI returns the value 513 as string, you should convert it to number, let's say it is v variable. Create a loop from 31 to 0, let's say for i variable. On each iteration, if v is greater than or equal to 2 ^ i then add the item with i key from dictionary to output array, and decrease v by 2 ^ i. As the result the output array contains the items from the dictionary which keys correspond the numbers of switched on bits in incoming value.

Community
  • 1
  • 1
omegastripes
  • 12,351
  • 4
  • 45
  • 96
  • Thanks for the answer. However, I am looking for the implementation where 513 is passed as parameter, will change to binary (1000000001) and then fetch the corresponding value from the above mapping. Consider the above bit result is saved in some dictionary or enum. I am not able to correlate the binary values to bits defined above. I am using C# as a choice programming language. – Leo Feb 10 '17 at 20:47
  • @Leo check my answer, I added description of the function you asked. – omegastripes Feb 10 '17 at 22:45
0

I had to accomplish this same task in python, but you can easily take this and turn it into other languages:

def bit_mapper(flag,goal="translate",check_bit=int):
    bit_map_dic = {
        "0":"Script",
        "1":"Account Disabled",
        "3":"Home Dir Required",
        "4":"Lockout",
        "5":"Password Not Required",
        "6":"Paswword Can't Change",
        "7":"Encrypted Test Password Allowed",
        "8":"Temp Duplicate Account",
        "9":"Normal Account",
        "11":"InterDomain Trust Account",
        "12":"WorkStation Trust Account",
        "13":"Server Trust Account",
        "16":"Don't Expire Password",
        "17":"MNS Logon Account",
        "18":"Smartcard Required",
        "19":"Trusted For Delegation",
        "20":"Not Delegated",
        "21":"Use DES Key Only",
        "22":"Don't Require Preauthorization",
        "23":"Password Expired"
    }
    flag=int(flag)
    map="{0:b}".format(flag)
    if goal == "translate":
        temp = []
        for bit in enumerate(map):
            if bit[1] is "1":
                temp.append(str(bit_map_dic[str(bit[0])]))
        return temp
    elif goal == "check":
        for bit in enumerate(map):
            if bit[0] == int(check_bit) and bit[1] is "1":
                return True
        return False

Two ways to call this function..

1.) If you want to map the Flag to words:

print bit_mapper("513")

2.) Check if a bit is set

print bit_mapper("513",goal="check",check_bit="9")

pm1391
  • 275
  • 2
  • 14