Delphi获取系统默认的UserAgent的方法


本文整理自网络,侵删。

 
/// <summary>
/// 获取系统默认的UserAgent
/// uses SHDocVw, MSHTML;
/// </summary>
function GetUserAgent: string;
var
  Doc: IHTMLDocument2;
  win: IHTMLWindow2;
  wb: TWebBrowser;
begin
  Result := '';
  try
    wb := TWebBrowser.Create(nil);
    try
      wb.Navigate('about:blank');
      while not wb.ReadyState = READYSTATE_COMPLETE do
        Application.ProcessMessages;
      Doc := IHTMLDocument2(wb.Document);
      if not Assigned(Doc) then Exit;
      win := Doc.parentWindow;
      if Assigned(win) then
        Result := win.clientInformation.userAgent;
    finally
      wb.Free;
    end;
  except
  end;
end;

注:此方法为获取系统默认的UserAgent的方法,而不一定是系统默认IE浏览器的UserAgent,如需获取IE浏览器的UserAgent,可将Webbrowser对象改为IWebBrowser2或IShellWindows等接口即可

相关阅读 >>

Delphi exe注入代码

Delphi 关闭icesword等

Delphi idftp ditdirectory未定义

Delphi 批量把图片保存到access数据库

Delphi doc转txt

Delphi cross socket的库

Delphi如何自动重启程序

Delphi图片增加文字水印

Delphi 10.3 中安装程序自动升级插件autoupgrader_pro_v5.2

Delphi读取android短信信息

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...