Get Active Directory User’s GUID and SID in C#? (Part 1)
Get the Current User’s Active Directory info?
Here is how to get the currently logged in users Active Directory GUID and SID.
Step 1 – Create a new Console Application project in Visual Studio.
Step 2 – Add a .NET reference to System.DirectoryServices.AccountManagement.
Step 3 – Populate the Main Method as shown below.
using System; using System.DirectoryServices.AccountManagement; namespace GetAdUserInfo { class Program { static void Main(string[] args) { Console.WriteLine("Name: " + UserPrincipal.Current.Name); Console.WriteLine("User: " + UserPrincipal.Current.UserPrincipalName); Console.WriteLine("GUID: " + UserPrincipal.Current.Guid); Console.WriteLine(" SID: " + UserPrincipal.Current.Sid); } } }
I'm looking for a way to obtain a "machine id" for every computer in the world. It needs to be unique (as possible). How stable, and how unique is the Current.Sid value?
If it is not suitable as a unique machine identifier...is there a way to obtain one through a different method?
Thanks for your help
[...] we learned how to Get the Current User’s Active Directory info. Today we will learn how to get a named user’s Active Directory [...]