public DateTime GetLastBootDateTimeObject(string host, ref DataGridViewRow row) { if (remoteOperationsUsesDCOM) { ManagementScope scope = GetWmiManagementScope(host); return(GetLasBoot(scope)); } else { /* * C:\Windows\system32>wmic path Win32_OperatingSystem get LastBootUpTime * LastBootUpTime * 20200830222819.410301-180 */ StreamReader executionOutput = null; DateTime lastBoot = default(DateTime); OperSystemUtils operUtils = new OperSystemUtils(remoteOperationsUsesDCOM); bool execResult = operUtils.ExecProcessViaPsExec(host, "wmic.exe", "path Win32_OperatingSystem get LastBootUpTime", out executionOutput); if (execResult) { string execOutputString = executionOutput.ReadToEnd(); lastBoot = ParseCIMDateTime(execOutputString.Replace("LastBootUpTime", "").Trim()); } return(lastBoot); } }
private void StartRebootInternalViaPsExec(string host, ref DataGridViewRow row) { object rebootResult = string.Empty; string rebootStatus = string.Empty; Color resultColor = Color.Black; try { DgvUtils.SetRowValue(ref row, WUCollums.Status, "OS Connecting"); StreamReader executionOutput = null; bool rebootIsInProgress = false; OperSystemUtils operUtils = new OperSystemUtils(remoteOperationsUsesDCOM); bool execResult = operUtils.ExecProcessViaPsExec(host, "shutdown.exe", "/r /t 0", out executionOutput); if (execResult) { string resultContent = executionOutput.ReadToEnd(); rebootIsInProgress = (resultContent == null || resultContent.Trim().Length == 0); if (rebootIsInProgress) { resultColor = Color.Black; rebootStatus = "OS Reboot completed"; rebootResult = ""; DgvUtils.SetRowValue(ref row, WUCollums.RebootRequired, false); } else { resultColor = Color.Red; rebootStatus = "OS Reboot error"; rebootResult = "Error: " + resultContent; } } } catch (Exception ex) { resultColor = Color.Red; rebootStatus = "OS Reboot error"; rebootResult = ex.Message; } finally { EndReboot(ref row); DgvUtils.SetRowStyleForeColor(ref row, WUCollums.OperationResults, resultColor); DgvUtils.SetRowValue(ref row, WUCollums.Status, rebootStatus); DgvUtils.SetRowValue(ref row, WUCollums.OperationResults, rebootResult); DgvUtils.SetRowValue(ref row, WUCollums.LastBoot, string.Empty); } }