您的位置:首页 > 其它

Access Windows XP SP2 Security Center via WMI

2006-09-18 04:49 429 查看
From http://www.pcmag.com/article2/0,1759,1639276,00.asp

According to Microsoft, WMI is the Microsoft implementation of Web-Based Enterprise Management (WBEM), an industry standard for accessing management information on a system. For Windows XP Service Pack 2, Microsoft added new fields or records to keep track of the Firewall and Antivirus information in the WMI database. The WMI database is designed to be accessible via the WBEM API (application program interface) and is available to any program that wants to access the WMI. These programs can be desktop applications written in desktop- or web-based scripting or ActiveX modules.

make a WMI query in root/SecurityCenter to find out which security product is installed in the system.
Set objSWbemServices = GetObject("winmgmts://./root/SecurityCenter")
Set colFirewall = objSWbemServices.ExecQuery("Select * From antivirusProduct",,48)
For Each objAntiVirusProduct In colFirewall
Echo(" " & objAntiVirusProduct.productUptoDate)
Next

You may also use the WbemScripting.SWbemLocator object

From http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21645145.html

Private Sub DumpFirewallInfo()

Dim oLocator As WbemScripting.SWbemLocator
Dim oService As WbemScripting.SWbemServicesEx
Dim oFirewalls As WbemScripting.SWbemObjectSet
Dim oFirewall As WbemScripting.SWbemObjectEx
Dim oFwMgr As Variant


Set oFwMgr = CreateObject("HNetCfg.FwMgr")

Debug.Print "Checking the Windows Firewall..."
Debug.Print "Windows Firewal Enabled: " & oFwMgr.LocalPolicy.CurrentProfile.FirewallEnabled
Debug.Print ""

Set oFwMgr = Nothing


Debug.Print "Checking for other installed firewalls..."

Set oLocator = New WbemScripting.SWbemLocator
Set oService = oLocator.ConnectServer(".", "root/SecurityCenter")
oService.Security_.ImpersonationLevel = 3

Set oFirewalls = oService.ExecQuery("SELECT * FROM FirewallProduct") ' This could also be "AntivirusProduct"

For Each oFirewall In oFirewalls
Debug.Print "Company: " & vbTab & oFirewall.CompanyName
Debug.Print "Firewall Name: " & vbTab & oFirewall.DisplayName
Debug.Print "Enabled: " & vbTab & Format$(oFirewall.Enabled)
Debug.Print "Version: " & vbTab & oFirewall.versionNumber
Debug.Print ""
Next oFirewall

Set oFirewall = Nothing
Set oFirewalls = Nothing
Set oService = Nothing
Set oLocator = Nothing

End Sub

more informatin about Wbem Scripting can be found at http://msdn.microsoft.com/library/en-us/wmisdk/wmi/creating_an_object_using_vbscript.asp.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: