using the .net library, you can use the following code to get the username or any information from the active directory
using System.Management; using System.Management.Instrumentation; using System.Runtime.InteropServices; using System.DirectoryServices; ManagementObjectSearcher Usersearcher = new ManagementObjectSearcher("Select * From Win32_ComputerSystem Where (Name LIKE 'ws%' or Name LIKE 'it%')"); ManagementObjectCollection Usercollection = Usersearcher.Get(); string[] sep = { "\\" }; string[] UserNameDomain = Usercollection.Cast<ManagementBaseObject>().First()["UserName"].ToString().Split(sep, StringSplitOptions.None);
i add "Select * From Win32_ComputerSystem Where (LIKE name 'ws%' or Name LIKE 'it%')" this will get the username with full name
hope this helps you
source share