LastBootUpTime
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
| program LastBootUpTime; {$APPTYPE CONSOLE}
uses SysUtils, ActiveX, Variants, ComObj;
function UtcToDateTime(const V : OleVariant): TDateTime; var Dt : OleVariant; begin Result:=0; if VarIsNull(V) then exit; Dt:=CreateOleObject('WbemScripting.SWbemDateTime'); Dt.Value := V; Result:=Dt.GetVarDate; end;
procedure GetWin32_OperatingSystemInfo; const WbemUser =''; WbemPassword =''; WbemComputer ='localhost'; wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword); FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_OperatingSystem','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; if oEnum.Next(1, FWbemObject, iValue) = 0 then begin Writeln(Format('Last BootUp Time %s',[FWbemObject.LastBootUpTime])); Writeln(Format('Last BootUp Time %s',[formatDateTime('dd-mm-yyyy hh:nn:ss',UtcToDateTime(FWbemObject.LastBootUpTime))])); end; end;
begin try CoInitialize(nil); try GetWin32_OperatingSystemInfo; finally CoUninitialize; end; except on E:Exception do Writeln(E.Classname, ':', E.Message); end; Writeln('Press Enter to exit'); Readln; end. |
Registry
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control]
"LastBootSucceeded"=dword:00000001
"LastBootShutdown"=dword:00000001
"DirtyShutdownCount"=dword:00000022
HKLM\SYSTEM\CurrentControlSet\Control\Windows\
ShutdownTime
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Windows]
"ShutdownTime"=hex:55,e8,79,55,86,d4,ce,01