Alternate solution:
Library needs to be inlcded is
System.Management
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(string.Format(@"\\{0}\ROOT\CIMV2",serverName), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_OperatingSystem");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
foreach (ManagementObject item in processClass.GetInstances())
{
Console.WriteLine(item["LastBootUpTime"].ToString());
}
For
ConnectionOptions
we can provide Domain, User Name and password for secure connections.