Get windows user SID from domain controller

I want to fetch the UserIdentity (or SID) from a Windows user from the domain, before they’ve logged into the system. Is this possible?

I know I can fetch the UserIdentity when the user is logged in by

LoginSettings ls = LoginSettingsCache.GetLoginSettings(EnvironmentManager.Instance.MasterSite);

The focus of this forum is on developing integrations to work with Milestone XProtect. When you are not logged in XProtect cannot help you and there are no methods in the MIP SDK for this.

I have an idea you might find answers that will allow you to get the information from Windows directly if you search other forums but this is a guess.

Sorry. For anyone else wondering, this is the answer:

using (var context = new PrincipalContext(ContextType.Domain, System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name))
            using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
            {
                searcher.QueryFilter = new UserPrincipal(context) { Name = "*" };
                foreach (var result in searcher.FindAll())
                {
                    // result.Sid
                }
            }