@@ -22,6 +22,8 @@ static pfnWldpGetApplicationSettingBoolean WldpGetApplicationSettingBoolean;
22
22
static pfnWldpQuerySecurityPolicy WldpQuerySecurityPolicy;
23
23
static PCWSTR NODEJS = L" Node.js" ;
24
24
static PCWSTR ENFORCE_CODE_INTEGRITY_SETTING_NAME = L" EnforceCodeIntegrity" ;
25
+ static PCWSTR DISABLE_INTERPRETIVE_MODE_SETTING_NAME =
26
+ L" DisableInteractiveMode" ;
25
27
26
28
void InitWldp (Environment* env) {
27
29
if (isWldpInitialized) {
@@ -101,6 +103,66 @@ static void IsFileTrustedBySystemCodeIntegrityPolicy(
101
103
args.GetReturnValue ().Set (isFileTrusted);
102
104
}
103
105
106
+ static void IsInteractiveModeDisabled (
107
+ const FunctionCallbackInfo<Value>& args) {
108
+ CHECK_EQ (args.Length (), 0 );
109
+
110
+ Environment* env = Environment::GetCurrent (args);
111
+
112
+ if (!isWldpInitialized) {
113
+ InitWldp (env);
114
+ }
115
+
116
+ if (WldpGetApplicationSettingBoolean != nullptr ) {
117
+ BOOL ret;
118
+ HRESULT hr = WldpGetApplicationSettingBoolean (
119
+ NODEJS,
120
+ DISABLE_INTERPRETIVE_MODE_SETTING_NAME,
121
+ &ret);
122
+
123
+ if (SUCCEEDED (hr)) {
124
+ args.GetReturnValue ().Set (
125
+ Boolean::New (env->isolate (), ret));
126
+ return ;
127
+ } else if (hr != E_NOTFOUND) {
128
+ // If the setting is not found, continue through to attempt
129
+ // WldpQuerySecurityPolicy, as the setting may be defined
130
+ // in the old settings format
131
+ args.GetReturnValue ().Set (Boolean::New (env->isolate (), false ));
132
+ return ;
133
+ }
134
+ }
135
+
136
+ // WldpGetApplicationSettingBoolean is the preferred way for applications to
137
+ // query security policy values. However, this method only exists on Windows
138
+ // versions going back to circa Win10 2023H2. In order to support systems
139
+ // older than that (down to Win10RS2), we can use the deprecated
140
+ // WldpQuerySecurityPolicy
141
+ if (WldpQuerySecurityPolicy != nullptr ) {
142
+ DECLARE_CONST_UNICODE_STRING (providerName, L" Node.js" );
143
+ DECLARE_CONST_UNICODE_STRING (keyName, L" Settings" );
144
+ DECLARE_CONST_UNICODE_STRING (valueName, L" DisableInteractiveMode" );
145
+ WLDP_SECURE_SETTING_VALUE_TYPE valueType =
146
+ WLDP_SECURE_SETTING_VALUE_TYPE_BOOLEAN;
147
+ ULONG valueSize = sizeof (int );
148
+ int ret = 0 ;
149
+ HRESULT hr = WldpQuerySecurityPolicy (
150
+ &providerName,
151
+ &keyName,
152
+ &valueName,
153
+ &valueType,
154
+ &ret,
155
+ &valueSize);
156
+ if (FAILED (hr)) {
157
+ args.GetReturnValue ().Set (Boolean::New (env->isolate (), false ));
158
+ return ;
159
+ }
160
+
161
+ args.GetReturnValue ().Set (
162
+ Boolean::New (env->isolate (), static_cast <bool >(ret)));
163
+ }
164
+ }
165
+
104
166
static void IsSystemEnforcingCodeIntegrity (
105
167
const FunctionCallbackInfo<Value>& args) {
106
168
CHECK_EQ (args.Length (), 0 );
@@ -168,6 +230,11 @@ static void IsFileTrustedBySystemCodeIntegrityPolicy(
168
230
args.GetReturnValue ().Set (true );
169
231
}
170
232
233
+ static void IsInterpretiveModeDisabled (
234
+ const FunctionCallbackInfo<Value>& args) {
235
+ args.GetReturnValue ().Set (false );
236
+ }
237
+
171
238
static void IsSystemEnforcingCodeIntegrity (
172
239
const FunctionCallbackInfo<Value>& args) {
173
240
args.GetReturnValue ().Set (false );
@@ -184,6 +251,12 @@ void Initialize(Local<Object> target,
184
251
" isFileTrustedBySystemCodeIntegrityPolicy" ,
185
252
IsFileTrustedBySystemCodeIntegrityPolicy);
186
253
254
+ SetMethod (
255
+ context,
256
+ target,
257
+ " isInteractiveModeDisabled" ,
258
+ IsInteractiveModeDisabled);
259
+
187
260
SetMethod (
188
261
context,
189
262
target,
@@ -193,6 +266,7 @@ void Initialize(Local<Object> target,
193
266
194
267
void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
195
268
registry->Register (IsFileTrustedBySystemCodeIntegrityPolicy);
269
+ registry->Register (IsInteractiveModeDisabled);
196
270
registry->Register (IsSystemEnforcingCodeIntegrity);
197
271
}
198
272
0 commit comments