Autor Beitrag
trm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 491
Erhaltene Danke: 19

Windows 7x64
Delphi 7
BeitragVerfasst: So 03.11.13 15:05 
Wo finde ich in der Registry Werte, wann die letzen male der PC herunter gefahren wurde?


Alternativ würde mir auch helfen, auszulesen, wann er die letzten male neu gebootet wurde.

Danke :)

_________________
In Erfurt gibt es eine Pension, in der es gemütlich ist, Google einfach nach Pension Fiege ;)
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 03.11.13 15:16 
LastBootUpTime

ausblenden volle Höhe Delphi-Quelltext
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;


//Universal Time (UTC) format of YYYYMMDDHHMMSS.MMMMMM(+-)OOO.
//20091231000000.000000+000
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]));// In utc format
    Writeln(Format('Last BootUp Time    %s',[formatDateTime('dd-mm-yyyy hh:nn:ss',UtcToDateTime(FWbemObject.LastBootUpTime))]));// Datetime
  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


Zuletzt bearbeitet von hathor am So 03.11.13 15:49, insgesamt 1-mal bearbeitet
trm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 491
Erhaltene Danke: 19

Windows 7x64
Delphi 7
BeitragVerfasst: So 03.11.13 15:46 
Hallo hathor,

danke für den Code. Leider ist es nicht das, was ich suchte. Es geht mir um Bootvorgänge außerhalb der aktuellen Session..


Edit: Habe gerade nochmal richtig gelesen,

HKLM\SYSTEM\CurrentControlSet\Control\Windows\ShutdownTime

hatte ich übersehen. Ich teste es mal :)

Gruß Mathias

_________________
In Erfurt gibt es eine Pension, in der es gemütlich ist, Google einfach nach Pension Fiege ;)