Inno Setup检查是否安装了防病毒软件

时间:2013-07-13 09:38:30

标签: inno-setup antivirus

有没有办法检查是否使用Inno Setup安装了防病毒软件?

1 个答案:

答案 0 :(得分:2)

您可以使用AntiVirusProduct WMI类,具体取决于您必须连接到root\SecurityCenterroot\SecurityCenter2命名空间的窗口版本。

有关详细信息,请查看此文章 Getting the installed Antivirus, AntiSpyware and Firewall software using Delphi and the WMI

注意:Windows桌面版(Windows XP,Windows Vista,7,8)仅支持AntiVirusProduct WMI类。

试试这个样本。

function IsAntivirusInstalled: Boolean;
var
    FSWbemLocator: Variant;
    FWMIService   : Variant;
    FWbemObjectSet: Variant;
    Version: TWindowsVersion;
begin 
    GetWindowsVersionEx(Version);    
    Result := false;
    FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');

    if (Version.Major = 5) and (Version.Minor = 1) then //Windows XP
      FWMIService := FSWbemLocator.ConnectServer('', 'root\SecurityCenter', '', '')
    else
    if (Version.Major = 6) then 
      FWMIService := FSWbemLocator.ConnectServer('', 'root\SecurityCenter2', '', '')
    else
    exit;

    FWbemObjectSet := FWMIService.ExecQuery('SELECT displayName FROM AntiVirusProduct');
    Result := (FWbemObjectSet.Count > 0);
    FWbemObjectSet := Unassigned;
    FWMIService := Unassigned;
    FSWbemLocator := Unassigned;
end;