开发者

Windows security Center API

开发者 https://www.devze.com 2023-04-12 00:06 出处:网络
I wo开发者_C百科uld like to access the Windows Security Center to check the status of several security features.

I wo开发者_C百科uld like to access the Windows Security Center to check the status of several security features.

Examples:

  • Firewall status
  • Whether Windows is up to date
  • Whether the computer has virus protection

How am I able to do this?

2003, XP, vista, 7


On Vista+ you can get a summary of its status via WscGetSecurityProviderHealth.


#include <Windows.h>
#include <string>
#include <iostream>
#include <Wscapi.h>
#pragma comment(lib, "Wscapi.lib")
using namespace std;

string printStatus(WSC_SECURITY_PROVIDER_HEALTH status)
{
  switch (status)
  {
  case WSC_SECURITY_PROVIDER_HEALTH_GOOD: return "GOOD";
  case WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED: return "NOTMONITORED";
  case WSC_SECURITY_PROVIDER_HEALTH_POOR: return "POOR";
  case WSC_SECURITY_PROVIDER_HEALTH_SNOOZE: return "SNOOZE";
  default: return "Status Error";
  }
}

void getHealth()
{
  WSC_SECURITY_PROVIDER_HEALTH health;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_FIREWALL, &health))
    cout << "FIREWALL:          " << printStatus(health) << endl;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS, &health))
    cout << "AUTOUPDATE:        " << printStatus(health) << endl;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_ANTIVIRUS, &health))
    cout << "ANTIVIRUS:         " << printStatus(health) << endl;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_ANTISPYWARE, &health))
    cout << "ANTISPYWARE:       " << printStatus(health) << endl;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_INTERNET_SETTINGS, &health))
    cout << "INTERNET SETTINGS: " << printStatus(health) << endl;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_USER_ACCOUNT_CONTROL, &health))
    cout << "UAC:               " << printStatus(health) << endl;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_SERVICE, &health))
    cout << "SERVICE:           " << printStatus(health) << endl;
  if (S_OK == WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_ALL, &health))
    cout << "ALL:               " << printStatus(health) << endl;

}

void main()
{
  getHealth();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号