private static List<string> GetNamesOfUserProfiles()
{
List<string> userNames = new List<string>();
string[] names = Registry.Users.GetSubKeyNames();
for (int i = 1; i < names.Length; i++)
{
try
{
SecurityIdentifier sid = new SecurityIdentifier(names[i]);
string userName = sid.Translate(typeof(NTAccount)).ToString();
int indexofDomain = userName.IndexOf('\\');
if (indexofDomain != -1)
{
userName = userName.Substring(indexofDomain + 1);
userNames.Add(userName);
}
}
catch (Exception) { }
}
return userNames;
}
}