unit WebBrowserRela;

uses
  Windows;

interface

function WriteAppNameToReg: Boolean;

implementation

function IsWin64:Boolean;//这个是别人写好的，不记得原出处了，见凉
var
 Kernel32Handle:THandle;
 //IsWow64Process: function(Handle:Windows.THandle;var Res:Windows.BOOL):Windows.BOOL; stdcall;
 //GetNativeSystemInfo: procedure(var lpSystemInfo:TSystemInfo);stdcall;
 isWoW64: Bool;
 SystemInfo: TSystemInfo;
const
 PROCESSOR_ARCHITECTURE_AMD64=9;
 PROCESSOR_ARCHITECTURE_IA64=6;
begin
  Kernel32Handle:=GetModuleHandle('KERNEL32.DLL');
  if Kernel32Handle=0 then
     Kernel32Handle:=LoadLibrary('KERNEL32.DLL');
  if Kernel32Handle<>0 then
  begin
    IsWOW64Process:=GetProcAddress(Kernel32Handle,'IsWow64Process');
    GetNativeSystemInfo:=GetProcAddress(Kernel32Handle,'GetNativeSystemInfo');
    if Assigned(IsWow64Process) then
    begin
      IsWow64Process(GetCurrentProcess,isWoW64);
      Result:=isWoW64 and Assigned(GetNativeSystemInfo);
      if Result then
      begin
         GetNativeSystemInfo(SystemInfo);
         Result:=(SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_AMD64)or
         (SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_IA64);
      end;
    end
    else
    Result:=False;
  end
  else
  Result:=False;
end;

function GetIEVersionStr: string;
var
 Reg: TRegistry; // registry access object
begin
 Result := '';
 Reg := TRegistry.Create;
 try
    Reg.RootKey := Windows.HKEY_LOCAL_MACHINE;
 if Reg.OpenKeyReadOnly('Software\Microsoft\Internet Explorer') then
 begin
  //这儿新版本IE的取值位置不同所以要判断 <br> if Reg.ValueExists('svcVersion') then
    Result := Reg.ReadString('svcVersion')
   else
   if Reg.ValueExists('Version') then
    Result := Reg.ReadString('Version');
 end;
 finally
   Reg.Free;
 end;
end;

function WriteAppNameToReg:Boolean;
var
  reg:TRegistry;
  sPath,sAppName:String;
  Sver:string;
  lenver:Integer;
begin
  Result:=True;
  reg:=TRegistry.Create;
  try
    reg.RootKey:=HKEY_LOCAL_MACHINE;
    sPath:='SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';
    if isWin64 then
      sPath:='SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';
    if reg.OpenKey(sPath,True) then
    begin
      sAppName:=ExtractFileName(Application.ExeName);
      Sver:=GetIEVersionStr;
      lenver:=StrToInt(leftstr(Sver, Pos('.',Sver)-1));
      // if not reg.ValueExists(sAppName)then
      if lenver<=7 then
        reg.WriteInteger(sAppName,7000)
      else if lenver=8 then
        reg.WriteInteger(sAppName,8000)
      else if lenver=9 then
        reg.WriteInteger(sAppName,9000)
      else if lenver=10 then
        reg.WriteInteger(sAppName,10000)
      else if lenver=11 then
        reg.WriteInteger(sAppName,11001);
    end;
    reg.CloseKey;
  finally
    FreeAndNil(reg);
  end;
end;

end.
