tags:

views:

212

answers:

2

How to detecting .net framework version with Delphi 7 ?

+2  A: 

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

RRUZ