Opc.Ua.Configuration.AccountInfo.LookupDomainSid C# (CSharp) Method

LookupDomainSid() public static method

Queries the SID table for the specified account name.
public static LookupDomainSid ( string domainName ) : string
domainName string
return string
        public static string LookupDomainSid(string domainName)
        {          
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("DomainName='{0}'", domainName);

            SelectQuery query = new SelectQuery("Win32_NTDomain", builder.ToString());  
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
            
            try
            {
                foreach (ManagementObject target in searcher.Get())
                {
                    return target["SID"] as string;
                }
            }
            finally
            {
                searcher.Dispose();
            }

            return null;
        }