How to detecting .net framework version with Delphi 7
How to detecting .net framework开发者_如何转开发 version with Delphi 7 ?
You can check the windows registry to detect wich version of the net framework is installed.
See this code
program DetectNetFrameWork;
{$APPTYPE CONSOLE}
uses
Windows,
Registry,
SysUtils;
const
NetFrameworkv1 ='SOFTWARE\Microsoft\.NETFramework\policy\v1.0';
NetFrameworkv1_1 ='SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322';
NetFrameworkv2 ='SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727';
NetFrameworkv3 ='SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0';
NetFrameworkv3_5 ='SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5';
NetFrameworkv4 ='SOFTWARE\Microsoft\NET Framework Setup\NDP\v4';
function NetFrameworkInstalled(NetFrameWorkId:String): Boolean;
var
Reg: TRegistry;
begin
Result := False;
Reg := TRegistry.Create(KEY_READ);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Result := Reg.KeyExists(NetFrameWorkId);
finally
Reg.Free;
end
end;
function BoolToStr(Val : Boolean): String;
begin
if val then
result := 'True'
else
result := 'False';
end;
begin
Writeln('Net Framework 1.0 Installed = '+BoolToStr(NetFrameworkInstalled(NetFrameworkv1)));
Writeln('Net Framework 1.1 Installed = '+BoolToStr(NetFrameworkInstalled(NetFrameworkv1_1)));
Writeln('Net Framework 2.0 Installed = '+BoolToStr(NetFrameworkInstalled(NetFrameworkv2)));
Writeln('Net Framework 3.0 Installed = '+BoolToStr(NetFrameworkInstalled(NetFrameworkv3)));
Writeln('Net Framework 3.5 Installed = '+BoolToStr(NetFrameworkInstalled(NetFrameworkv3_5)));
Writeln('Net Framework 4.0 Installed = '+BoolToStr(NetFrameworkInstalled(NetFrameworkv4)));
Readln;
end.
you can check theses links for more info
- Detecting .NET with Delphi by Bob Swart
- How to detect what .NET Framework versions and service packs are installed?
How to detect what .NET Framework versions and service packs are installed?
Extending answer of @RRUZ to 4.5 & 4.6, GetDOTNETVersion returns highest installed .NET version.
function GetDOTNETVersion: string;
function NetFrameworkInstalled(NetFrameWorkId: String): string;
begin
Result := '0';
with TRegistry.Create(KEY_READ) do
try
RootKey := HKEY_LOCAL_MACHINE;
if KeyExists(NetFrameWorkId) then
try
OpenKeyReadOnly(NetFrameWorkId);
Result := ReadString('Version');
if Result.IsEmpty then // v4 & v4.0
begin
CloseKey;
OpenKeyReadOnly(NetFrameWorkId+'\Client');
Result := ReadString('Version');
end;
finally
CloseKey;
end;
finally
Free;
end;
end;
const
NetFrameworkv1 = 'SOFTWARE\Microsoft\.NETFramework\policy\v1.0';
NetFrameworkv1_1 = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322';
NetFrameworkv2 = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727';
NetFrameworkv3 = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0';
NetFrameworkv3_5 = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5';
NetFrameworkv4_0 = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0';
NetFrameworkv4 = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4';
begin
Result := NetFrameworkInstalled(NetFrameworkv4);
if Result.IsEmpty then Result := NetFrameworkInstalled(NetFrameworkv4_0);
if Result.IsEmpty then Result := NetFrameworkInstalled(NetFrameworkv3_5);
if Result.IsEmpty then Result := NetFrameworkInstalled(NetFrameworkv3);
if Result.IsEmpty then Result := NetFrameworkInstalled(NetFrameworkv2);
if Result.IsEmpty then Result := NetFrameworkInstalled(NetFrameworkv1_1);
if Result.IsEmpty then Result := NetFrameworkInstalled(NetFrameworkv1);
end;
精彩评论