public static List GetSysUserNames()
{
List temp = new List();
string iuser = "";
string lastLogin = "";
GetLastLoginTime = new List();
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
options.EnablePrivileges = true;
ManagementScope scope = new ManagementScope("\\root\\cimv2", options);
scope.Options.EnablePrivileges = true;
scope.Options.Impersonation = ImpersonationLevel.Impersonate;
scope.Connect();
SelectQuery query = new SelectQuery("Select * from Win32_NetworkLoginProfile ");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
foreach (ManagementBaseObject useraccount in searcher.Get())
{
iuser = useraccount["Name"].ToString();
if (!iuser.Trim().StartsWith("NT AUTHORITY") && !iuser.Trim().Equals(""))
{
if (useraccount["LastLogon"] == null)
{
lastLogin = "00/00/0000";
}
else
{
if (useraccount["LastLogon"].ToString().Contains("*"))
{
lastLogin = "00/00/0000";
}
else
{
lastLogin = useraccount["LastLogon"].ToString().Substring(0, 8);
}
}
GetLastLoginTime.Add(CastLastLoginFormat(lastLogin));
temp.Add(iuser);
}
}
return temp;
}