In .NET 8.0 I can do the following to fetch the last boot time of the PC:
public static DateTime? GetLastBootTime()
{
DateTime? dtBootTime = null;
SelectQuery query = new SelectQuery(@"SELECT LastBootUpTime FROM Win32_OperatingSystem WHERE Primary='true'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get())
{
dtBootTime = ManagementDateTimeConverter.ToDateTime(mo.Properties["LastBootUpTime"].Value.ToString());
}
return dtBootTime;
}
This works great but I want to have this code in a shared class which is using netstandard2.0.
Is it possible to somehow do the same thing but in .NET Standard 2.0? I though TickCount64 could work but its not available in net standard.
ManagementObjectSearcherdoes exist in .NET Framework