| 12
 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
 
 |  
//------------------------------------------------------------------------------------------------------------------------------
Procedure TFormApp.CheckWindowsUpdate;
// Sur Windows 10: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\WindowsUpdate\AU\ puis AUOptions
// ------------------
// Valeur de AUOptions:
// 1 = Never
// 2 = Notify before download = Check for updates but let me choose whether to download and install them
// 3 = Automatically download and notify of installation = Download updates but let me choose whether to install them
// 4 = Automatic download and scheduled installation. (Only valid if values exist for ScheduledInstallDay and ScheduledInstallTime.) = Install updates automatically.
// 5 = Automatic Updates is required, but end users can configure it.
// ------------------
 
Const
 KEY_WOW64_64KEY = $0100;
 CleWIN7  = 'SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update';
 CleWIN10 = 'SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU';
var
 Key   : HKey;
 Pcode : array[0..255] of char;
 Taille: cardinal;
 li : longint;
 flag: REGSAM;
 wow64: BOOL;
 AUOptions : byte;
//----------------------------------
Function ReadOptions:byte;
Begin
  result := 0;
  li := RegQueryValueEx(Key, Pchar('AUOptions'), nil, nil, @Pcode, @Taille);
  if (li=ERROR_SUCCESS)	then result:=byte(Pcode[0]);
End;
//----------------------------------
Begin
  flag := 0;
  wow64 := false;
  IsWow64Process(GetCurrentProcess(), @wow64);
  if wow64 then flag := KEY_WOW64_64KEY;
 
  taille:=sizeof(Pcode);                           // KEY_QUERY_VALUE
  AUOptions := 0;
  if (AUOptions=0) and (RegOpenKeyEx(HKEY_LOCAL_MACHINE,Pchar(CleWin7), 0, KEY_QUERY_VALUE or flag, Key) = ERROR_SUCCESS) then AUOptions := ReadOptions;
  if (AUOptions=0) and (RegOpenKeyEx(HKEY_LOCAL_MACHINE,Pchar(CleWIN10),0, KEY_QUERY_VALUE or flag, Key) = ERROR_SUCCESS) then AUOptions := ReadOptions;
  if (AUOptions>=4) then
  Begin
     MyLog.LogEvent('',-1,li_OS_INFO, LOG_GENERAL, EL_WARNING,'Please check windows update because the computer may reboot automatically');
  End;
End;
//------------------------------------------------------------------------------------------------------------------------------ | 
Partager