2Copyright 2021 Intel Corporation
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
18var WSC_SECURITY_PROVIDER_FIREWALL = 0x1;
19var WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS = 0x2;
20var WSC_SECURITY_PROVIDER_ANTIVIRUS = 0x4;
21var WSC_SECURITY_PROVIDER_ANTISPYWARE = 0x8;
23var WSC_SECURITY_PROVIDER_HEALTH_GOOD = 0; // Green pillar in English locales
24var WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED = 1; // Yellow pillar in English locales
25var WSC_SECURITY_PROVIDER_HEALTH_POOR = 2; // Red pillar in English locales
26var WSC_SECURITY_PROVIDER_HEALTH_SNOOZE = 3; // Yellow pillar in English locales
30 seccenter = require('_GenericMarshal').CreateNativeProxy('Wscapi.dll');
31 seccenter.CreateMethod('WscGetSecurityProviderHealth');
32 seccenter.CreateMethod('WscRegisterForChanges');
33 seccenter.CreateMethod('WscUnRegisterChanges');
39function statusString(val)
63 var ret = { firewall: 'UNKNOWN', antiVirus: 'UNKNOWN', autoUpdate: 'UNKNOWN' };
64 if (seccenter != null)
66 var status = require('_GenericMarshal').CreateVariable(4);
67 if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_FIREWALL, status).Val == 0) { ret.firewall = statusString(status.toBuffer().readUInt32LE()); }
68 if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_ANTIVIRUS, status).Val == 0) { ret.antiVirus = statusString(status.toBuffer().readUInt32LE()); }
69 if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS, status).Val == 0) { ret.autoUpdate = statusString(status.toBuffer().readUInt32LE()); }
74if (process.platform == 'win32' && seccenter != null)
76 var j = { status: getStatus };
77 require('events').EventEmitter.call(j, true)
78 .createEvent('changed');
79 j._H = require('_GenericMarshal').CreatePointer();
80 j._EV = require('_GenericMarshal').GetGenericGlobalCallback(1);
82 j._EV.on('GlobalCallback', function (p)
84 if (!this.ObjectToPtr_Verify(this.parent, p)) { return; } // This event is not for us
85 this.parent.emit('changed');
89 if (seccenter.WscUnRegisterChanges(this._H).Val == 0) { }
92 if (seccenter.WscRegisterForChanges(0, j._H, j._EV, require('_GenericMarshal').ObjectToPtr(j)).Val == 0)
100 throw ('win-securitycenter not supported on this platform');