2009-08-26 30 views
22

C#を使用してコンピュータにウイルス対策ソフトウェアがインストールされているかどうかを検出する方法はありますか?私はセキュリティセンターがウイルス対策ソフトウェアを検出することを知っていますが、C#でそれをどのように検出できますか?C#を使用してWindows上でウイルス対策ソフトウェアを検出する

+0

かどうかを知るためにどのような方法がありますwindows [email protected]のシステム上でウイルス対策ソフトウェアが更新されます。 ng.47 – TechBrkTru

+0

WMIを使用できます。 [ここ](http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/bd97d9e6-75c1-4f58-9573-9009df5de19b)を参照してください。 – SLaks

答えて

31

マイクロソフトによると、Windowsセキュリティセンターでは、2段階のアプローチで検出ステータスが使用されています。 1つのティアは手動であり、もう1つのティアはWMI(Windows Management Instrumentation)を通じて自動です。手動検出モードでは、Windowsセキュリティセンターは独立したソフトウェアメーカーによってMicrosoftに提供されるレジストリキーとファイルを検索します。これらのレジストリキーとファイルを使用すると、Windowsセキュリティセンターは独立したソフトウェアの状態を検出できます。 WMIモードでは、ソフトウェア製造元が独自の製品ステータスを判断し、そのステータスをWMIプロバイダを介してWindowsセキュリティセンターに報告します。どちらのモードでも、Windowsセキュリティセンターは以下の条件が満たされているかどうかを確認しようとします。

ウイルス対策プログラムが存在します。

ウイルス対策シグネチャは最新です。

ウイルス対策プログラムのリアルタイムスキャンまたはオンアクセススキャンがオンになっています。

ファイアウォールの場合、Windowsセキュリティセンターは、サードパーティのファイアウォールがインストールされているかどうか、およびファイアウォールが有効かどうかを検出します。

だから、ウイルス対策ソフトウェアの存在を決定するために、あなたは(Windows Vistaの始まるあなたはroot\SecurityCenter2名前空間を使用する必要があります)root\SecurityCenter名前空間に接続するWMIを使用することができ、その後、AntiVirusProduct WMIクラスに対してクエリを実行。このサンプルコード

using System; 
using System.Text; 
using System.Management; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
    public static bool AntivirusInstalled() 
    { 

     string wmipathstr = @"\\" + Environment.MachineName + @"\root\SecurityCenter"; 
     try 
     { 
     ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmipathstr, "SELECT * FROM AntivirusProduct"); 
     ManagementObjectCollection instances = searcher.Get(); 
     return instances.Count > 0; 
     } 

     catch (Exception e) 
     { 
     Console.WriteLine(e.Message); 
     } 

     return false; 
    } 

    public static void Main(string[] args) 
    { 
     bool returnCode = AntivirusInstalled(); 
     Console.WriteLine("Antivirus Installed " + returnCode.ToString()); 
     Console.WriteLine(); 
     Console.Read(); 
    } 

    } 
} 
+1

Windows 7でこれを行う方法はありますか? – aHunter

+3

Windows 7では '\ root \ SecurityCenter2'名前空間を使用する必要があります – RRUZ

+0

Windowsサーバー2008で試しましたが、「無効な名前空間」という例外が発生しています。それはWindows 7で動作します。 – Rahil

3

ルックWMIクエリは、VistaのSP2にし、超えて少し変化します。

は、結果が同様に若干異なりますSecurityCenter2 の代わりに、\ルートの\ SecurityCenterの

\この部分の\のルートを試してみてください。表示名を取得することはできますが、ProductStateフィールドのビットマスキングを少し行い、onAccessScannerが有効か無効か、upToDateの種類の情報かを判断する必要があります。

2

C:\Windows\System32\wbem\wscenter.mofをメモ帳で開く。これは、名前空間とクラスが存在するのに役立ちます:


C#のクエリ: wscenter.mof

// SELECT * FROM AntiVirusProduct 
// SELECT * FROM FirewallProduct 
// SELECT * FROM AntiSpywareProduct 
ManagementObjectSearcher wmiData = new ManagementObjectSearcher(@"root\SecurityCenter2", "SELECT * FROM AntiVirusProduct"); 
ManagementObjectCollection data = wmiData.Get(); 

foreach (ManagementObject virusChecker in data) 
{ 
    var virusCheckerName = virusChecker["displayName"]; 
} 

#pragma autorecover 
#pragma classflags(64) 
#pragma namespace("\\\\.\\root") 

[NamespaceSecuritySDDL("O:S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464G:S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464D:(A;CI;0x1;;;BU)(A;CI;0x1;;;BA)(A;CI;0x1;;;NS)(A;CI;0x1;;;LS)(A;CI;0x1;;;AU)(A;CI;0x6001D;;;S-1-5-80-3232712927-1625117661-2590453128-1738570065-3637376297)")] 
Instance of __namespace 
{ 
    Name = "SecurityCenter"; 
}; 

[NamespaceSecuritySDDL("O:S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464G:S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464D:(A;CI;0x1;;;BU)(A;CI;0x1;;;BA)(A;CI;0x1;;;NS)(A;CI;0x1;;;LS)(A;CI;0x1;;;AU)(A;CI;0x6001D;;;S-1-5-80-3232712927-1625117661-2590453128-1738570065-3637376297)")] 
Instance of __namespace 
{ 
    Name = "SecurityCenter2"; 
}; 
#pragma namespace("\\\\.\\root\\SecurityCenter") 

class AntiVirusProduct 
{ 
    [key,Not_Null] string instanceGuid; 
    [Not_Null] string displayName; 
    [Not_Null] boolean productUptoDate; 
    boolean onAccessScanningEnabled; 
    boolean productHasNotifiedUser; 
    boolean productWantsWscNotifications; 
    uint8 productState; 
    string companyName; 
    string versionNumber; 
    string pathToSignedProductExe; 
}; 

class FirewallProduct 
{ 
    [key,Not_Null] string instanceGuid; 
    [Not_Null] string displayName; 
    boolean enabled; 
    boolean productHasNotifiedUser; 
    boolean productWantsWscNotifications; 
    uint8 productState; 
    string companyName; 
    string versionNumber; 
    string pathToSignedProductExe; 
}; 

class AntiSpywareProduct 
{ 
    [key,Not_Null] string instanceGuid; 
    [Not_Null] string displayName; 
    [Not_Null] boolean productUptoDate; 
    boolean productEnabled; 
    boolean productHasNotifiedUser; 
    boolean productWantsWscNotifications; 
    uint8 productState; 
    string companyName; 
    string versionNumber; 
    string pathToSignedProductExe; 
}; 
#pragma namespace("\\\\.\\root\\SecurityCenter2") 

class AntiVirusProduct 
{ 
    [key,Not_Null] string instanceGuid; 
    [Not_Null] string displayName; 
    [Not_Null] string pathToSignedProductExe; 
    [Not_Null] string pathToSignedReportingExe; 
    [Not_Null] uint32 productState; 
    string timestamp; 
}; 

class FirewallProduct 
{ 
    [key,Not_Null] string instanceGuid; 
    [Not_Null] string displayName; 
    [Not_Null] string pathToSignedProductExe; 
    [Not_Null] string pathToSignedReportingExe; 
    [Not_Null] uint32 productState; 
    string timestamp; 
}; 

class AntiSpywareProduct 
{ 
    [key,Not_Null] string instanceGuid; 
    [Not_Null] string displayName; 
    [Not_Null] string pathToSignedProductExe; 
    [Not_Null] string pathToSignedReportingExe; 
    [Not_Null] uint32 productState; 
    string timestamp; 
}; 
#pragma autorecover 
関連する問題