I need to be able to convert into days the long datetime string returned by the following wmi query:
SelectQuery query = new SelectQuery("SELECT * FROM Win32_NetworkLoginProfile");
The propety name is PasswordAge.
PasswordAge Data type: datetime
Length of time a password has been in effect. This value is measured from the number of seconds elapsed since the password was last changed.
Example: 00000011171549.000000:000
ManagementScope scope = CreateNewManagementScope(computerName);
SelectQuery query = new SelectQuery("SELECT Name, PasswordAge FROM Win32_NetworkLoginProfile WHERE Privileges=2 ");
try
{
using (var searcher = new ManagementObjectSearcher(scope, query))
{
ManagementObjectCollection accounts = searcher.Get();
List<string> accountNames = new List<string>();
foreach (ManagementObject account in accounts)
{
string name = account["Name"].ToString();
string pAge = account["PasswordAge"].ToString();
accountNames.Add(name + " " + pAge);
}
lstAccounts.DataSource = accountNames;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…