onlyou13

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
function IsWOW64: BOOL;
begin
  Result := False;
  if GetProcAddress(GetModuleHandle(kernel32), 'IsWow64Process') <> nil then
    IsWow64Process(GetCurrentProcess, Result);
end;

procedure SetProgramIEVersion(processName: string; ver: Integer);
var
  ARegistry: TRegistry;
  list: TStringList;
  verValue: Integer;
  key: string;
const
  x86Key = 'SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';
  x64Key = 'SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';
begin
  list := TStringList.Create;
  try
    list.AddPair('11', '11000');
    list.AddPair('10', '10001');
    list.AddPair('9', '9999');
    list.AddPair('8', '8888');
    list.AddPair('7', '7000');

    if list.IndexOfName(IntToStr(ver)) >= 0 then
      verValue := StrToInt(list.Values[IntToStr(ver)])
    else verValue := 10;

    if processName = '' then
      processName := ExtractFileName(ParamStr(0));

    if IsWOW64 then
      key := x64Key
    else key := x86Key;

    ARegistry := TRegistry.Create;
    with ARegistry do
    try
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKey(key, True) then
      begin
        if ValueExists(processName) then
          DeleteValue(processName);
        WriteInteger(processName, verValue);
      end;
      CloseKey;
    finally
      Free;
    end;
  finally
    list.Free;
  end;

 

 

调用方式:

SetProgramIEVersion('a.exe', 11); 

如果是设置自身程序:

SetProgramIEVersion('', 11);

posted on 2019-08-28 22:09  onlyou13  阅读(265)  评论(0编辑  收藏  举报