/* Copyright 2021 Intel Corporation @author Bryan Roe Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ const CUSTOM_HANDLER = 0x80000000; const GM = require('_GenericMarshal'); const CLSID_TaskScheduler = '{0f87369f-a4e5-4cfc-bd3e-73e6154572dd}'; const IID_TimeTrigger = '{b45747e0-eba7-4276-9f29-85c5bb300006}'; const IID_ExecAction = '{4c3d624d-fd6b-49a3-b9b7-09cb3cd3f047}'; const VT_EMPTY = 0; const VT_NULL = 1; const VT_SAFEARRAY = 27; const VT_BSTR = 8; const VT_ARRAY = 0x2000; const TASK_LOGON_NONE = 0; const TASK_LOGON_PASSWORD = 1; const TASK_LOGON_S4U = 2; const TASK_LOGON_INTERACTIVE_TOKEN = 3; const TASK_LOGON_GROUP = 4; const TASK_LOGON_SERVICE_ACCOUNT = 5; const TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD = 6; const TASK_TRIGGER_EVENT = 0; const TASK_TRIGGER_TIME = 1; const TASK_TRIGGER_DAILY = 2; const TASK_TRIGGER_WEEKLY = 3; const TASK_TRIGGER_MONTHLY = 4; const TASK_TRIGGER_MONTHLYDOW = 5; const TASK_TRIGGER_IDLE = 6; const TASK_TRIGGER_REGISTRATION = 7; const TASK_TRIGGER_BOOT = 8; const TASK_TRIGGER_LOGON = 9; const TASK_TRIGGER_SESSION_STATE_CHANGE = 11; const TASK_TRIGGER_CUSTOM_TRIGGER_01 = 12; const TASK_ACTION_EXEC = 0; const TASK_ACTION_COM_HANDLER = 5; const TASK_ACTION_SEND_EMAIL = 6; const TASK_ACTION_SHOW_MESSAGE = 7; const TASK_VALIDATE_ONLY = 0x1; const TASK_CREATE = 0x2; const TASK_UPDATE = 0x4; const TASK_CREATE_OR_UPDATE = (TASK_CREATE | TASK_UPDATE); const TASK_DISABLE = 0x8; const TASK_DONT_ADD_PRINCIPAL_ACE = 0x10; const TASK_IGNORE_REGISTRATION_TRIGGERS = 0x20; var OleAut32 = GM.CreateNativeProxy('OleAut32.dll'); OleAut32.CreateMethod('SafeArrayAccessData'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-safearrayaccessdata OleAut32.CreateMethod('SafeArrayCreate'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-safearraycreate OleAut32.CreateMethod('SafeArrayCreateVector'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-safearraycreatevector OleAut32.CreateMethod('SafeArrayPutElement'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-safearrayputelement OleAut32.CreateMethod('SafeArrayDestroy'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-safearraydestroy OleAut32.CreateMethod('VariantClear'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-variantclear OleAut32.CreateMethod('VariantInit'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-variantinit OleAut32.CreateMethod('SysAllocString'); // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-sysallocstring // // This function converts an array of strings, to a variant array of BSTR // function ConvertStringArray(strarr) { if (!strarr || !Array.isArray(strarr)) { return (GM.CreateVariable(24)); } var i, tmp; var v = GM.CreateVariable(24); v._tmp = []; var ix = GM.CreateVariable(4); console.info1('strarr.length=' + strarr.length); var safe = OleAut32.SafeArrayCreateVector(VT_BSTR, 0, strarr.length); if(safe.Val == 0) { throw('Error creating SafeArray'); } for(i=0;i