uses Registry
var
Form1: TForm1;
FWinVerMaj : integer;
FWinVerMin : integer;
FWinBuild : integer;
FWinProdName : string;
//
function CheckWinVer(var WinVerMaj : integer;
var WinVerMin : integer;
var WinVerBuild : integer;
var WinProdName : string;
ShowMsg : boolean) : boolean;
var
reg: TRegistry; // USES: Registry
s1, s2 : string;
MemVerMaj : integer;
MemVerMin : integer;
MemVerBuild : integer;
MsgType : TMsgDlgType;
begin
result := true;
//MsgType := TMsgDlgType.mtInformation;
MemVerMaj := WinVerMaj;
MemVerMin := WinVerMin;
MemVerBuild := WinVerBuild;
reg := TRegistry.Create(KEY_READ);
reg.RootKey := HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion',false) then
begin
// since WIN 10:
try
WinVerMaj := reg.ReadInteger('CurrentMajorVersionNumber'); // dword:0000000a
WinVerMin := reg.ReadInteger('CurrentMinorVersionNumber'); // dword:00000000
except
WinVerMaj := -1;
WinVerMin := 0;
end;
if (WinVerMaj < 0) then
begin
s1 := reg.ReadString('CurrentVersion');
s2 := Copy(s1, 1, Pos('.', s1) - 1);
WinVerMaj := strtoint(s2);
s2 := Copy(s1, Pos('.', s1) + 1, length(s1));
WinVerMin := strtoint(s2);
end;
s1 := reg.ReadString('CurrentBuildNumber');
WinVerBuild := strtoint(s1);
WinProdName := reg.ReadString('ProductName');
s1 := 'OS-Version: ' + WinProdName + #10#13 +
inttostr(WinVerMaj) + '.' + inttostr(WinVerMin) + ' - Build ' + inttostr(WinVerBuild);
s2 := '';
// check necessaryVersion
if NOT (WinVerMaj >= MemVerMaj) then
begin
s2 := #10#13 + '-> Major-Version lower as expected ! (' + inttostr(MemVerMaj) + ')';
result := false;
end;
// if NOT (WinVerMin >= MemVerMin) then --- nicht ganz richtig ...
if (NOT (WinVerMaj > MemVerMaj)) AND (NOT (WinVerMin >= MemVerMin)) then
begin
s2 := s2 + #10#13 + ' Minor-Version lower as expected ! (' + inttostr(MemVerMin) + ')';
result := false;
end;
if NOT (WinVerBuild >= MemVerBuild) then
begin
s2 := s2 + #10#13 + ' Build-Nr. lower as expected ! (' + inttostr(MemVerBuild) + ')';
result := false;
end;
if NOT result then
//MsgType := TMsgDlgType.mtWarning;
end
else
begin
result := false;
//MsgType := TMsgDlgType.mtError;
WinVerMaj := -1;
WinVerMin := -1;
WinVerBuild := -1;
WinProdName := 'Unknown Version';
s1 := 'WARNING: Determine OS-Version failed !';
s2 := '';
end;
reg.CloseKey();
reg.Free;
//if ShowMsg then
begin
//MessageDlg(s1 + s2, MsgType, [mbOK], 0);
end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
CheckWinVer(FWinVerMaj, FWinVerMin, FWinBuild, FWinProdName, true);
Label1.Caption := FWinProdName;
Label2.Caption := IntToStr(FWinBuild);
Label3.Caption := IntToStr(FWinVerMin);
Label4.Caption := IntToStr(FWinVerMaj);
end;
Keine Kommentare:
Kommentar veröffentlichen