1 /*! *****************************************************************************
2 Copyright (c) Microsoft Corporation. All rights reserved.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the
5 License at http://www.apache.org/licenses/LICENSE-2.0
7 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 MERCHANTABLITY OR NON-INFRINGEMENT.
12 See the Apache Version 2.0 License for specific language governing permissions
13 and limitations under the License.
14 ***************************************************************************** */
18 /// <reference no-default-lib="true"/>
\r
23 /////////////////////////////
\r
24 /// Windows Script Host APIS
\r
25 /////////////////////////////
\r
28 interface ActiveXObject {
\r
29 new (s: string): any;
\r
31 declare var ActiveXObject: ActiveXObject;
\r
33 interface ITextWriter {
\r
34 Write(s: string): void;
\r
35 WriteLine(s: string): void;
\r
39 interface TextStreamBase {
\r
41 * The column number of the current character position in an input stream.
\r
46 * The current line number in an input stream.
\r
51 * Closes a text stream.
\r
52 * It is not necessary to close standard streams; they close automatically when the process ends. If
\r
53 * you close a standard stream, be aware that any other pointers to that standard stream become invalid.
\r
58 interface TextStreamWriter extends TextStreamBase {
\r
60 * Sends a string to an output stream.
\r
62 Write(s: string): void;
\r
65 * Sends a specified number of blank lines (newline characters) to an output stream.
\r
67 WriteBlankLines(intLines: number): void;
\r
70 * Sends a string followed by a newline character to an output stream.
\r
72 WriteLine(s: string): void;
\r
75 interface TextStreamReader extends TextStreamBase {
\r
77 * Returns a specified number of characters from an input stream, starting at the current pointer position.
\r
78 * Does not return until the ENTER key is pressed.
\r
79 * Can only be used on a stream in reading mode; causes an error in writing or appending mode.
\r
81 Read(characters: number): string;
\r
84 * Returns all characters from an input stream.
\r
85 * Can only be used on a stream in reading mode; causes an error in writing or appending mode.
\r
90 * Returns an entire line from an input stream.
\r
91 * Although this method extracts the newline character, it does not add it to the returned string.
\r
92 * Can only be used on a stream in reading mode; causes an error in writing or appending mode.
\r
97 * Skips a specified number of characters when reading from an input text stream.
\r
98 * Can only be used on a stream in reading mode; causes an error in writing or appending mode.
\r
99 * @param characters Positive number of characters to skip forward. (Backward skipping is not supported.)
\r
101 Skip(characters: number): void;
\r
104 * Skips the next line when reading from an input text stream.
\r
105 * Can only be used on a stream in reading mode, not writing or appending mode.
\r
110 * Indicates whether the stream pointer position is at the end of a line.
\r
112 AtEndOfLine: boolean;
\r
115 * Indicates whether the stream pointer position is at the end of a stream.
\r
117 AtEndOfStream: boolean;
\r
120 declare var WScript: {
\r
122 * Outputs text to either a message box (under WScript.exe) or the command console window followed by
\r
123 * a newline (under CScript.exe).
\r
125 Echo(s: any): void;
\r
128 * Exposes the write-only error output stream for the current script.
\r
129 * Can be accessed only while using CScript.exe.
\r
131 StdErr: TextStreamWriter;
\r
134 * Exposes the write-only output stream for the current script.
\r
135 * Can be accessed only while using CScript.exe.
\r
137 StdOut: TextStreamWriter;
\r
138 Arguments: { length: number; Item(n: number): string; };
\r
141 * The full path of the currently running script.
\r
143 ScriptFullName: string;
\r
146 * Forces the script to stop immediately, with an optional exit code.
\r
148 Quit(exitCode?: number): number;
\r
151 * The Windows Script Host build version number.
\r
153 BuildVersion: number;
\r
156 * Fully qualified path of the host executable.
\r
161 * Gets/sets the script mode - interactive(true) or batch(false).
\r
163 Interactive: boolean;
\r
166 * The name of the host executable (WScript.exe or CScript.exe).
\r
171 * Path of the directory containing the host executable.
\r
176 * The filename of the currently running script.
\r
178 ScriptName: string;
\r
181 * Exposes the read-only input stream for the current script.
\r
182 * Can be accessed only while using CScript.exe.
\r
184 StdIn: TextStreamReader;
\r
187 * Windows Script Host version
\r
192 * Connects a COM object's event sources to functions named with a given prefix, in the form prefix_event.
\r
194 ConnectObject(objEventSource: any, strPrefix: string): void;
\r
197 * Creates a COM object.
\r
198 * @param strProgiID
\r
199 * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events.
\r
201 CreateObject(strProgID: string, strPrefix?: string): any;
\r
204 * Disconnects a COM object from its event sources.
\r
206 DisconnectObject(obj: any): void;
\r
209 * Retrieves an existing object with the specified ProgID from memory, or creates a new one from a file.
\r
210 * @param strPathname Fully qualified path to the file containing the object persisted to disk.
\r
211 * For objects in memory, pass a zero-length string.
\r
213 * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events.
\r
215 GetObject(strPathname: string, strProgID?: string, strPrefix?: string): any;
\r
218 * Suspends script execution for a specified length of time, then continues execution.
\r
219 * @param intTime Interval (in milliseconds) to suspend script execution.
\r
221 Sleep(intTime: number): void;
\r
225 * WSH is an alias for WScript under Windows Script Host
\r
227 declare var WSH: typeof WScript;
\r
230 * Represents an Automation SAFEARRAY
\r
232 declare class SafeArray<T = any> {
\r
233 private constructor();
\r
234 private SafeArray_typekey: SafeArray<T>;
\r
238 * Allows enumerating over a COM collection, which may not have indexed item access.
\r
240 interface Enumerator<T = any> {
\r
242 * Returns true if the current item is the last one in the collection, or the collection is empty,
\r
243 * or the current item is undefined.
\r
248 * Returns the current item in the collection
\r
253 * Resets the current item in the collection to the first item. If there are no items in the collection,
\r
254 * the current item is set to undefined.
\r
259 * Moves the current item to the next item in the collection. If the enumerator is at the end of
\r
260 * the collection or the collection is empty, the current item is set to undefined.
\r
265 interface EnumeratorConstructor {
\r
266 new <T = any>(safearray: SafeArray<T>): Enumerator<T>;
\r
267 new <T = any>(collection: { Item(index: any): T }): Enumerator<T>;
\r
268 new <T = any>(collection: any): Enumerator<T>;
\r
271 declare var Enumerator: EnumeratorConstructor;
\r
274 * Enables reading from a COM safe array, which might have an alternate lower bound, or multiple dimensions.
\r
276 interface VBArray<T = any> {
\r
278 * Returns the number of dimensions (1-based).
\r
280 dimensions(): number;
\r
283 * Takes an index for each dimension in the array, and returns the item at the corresponding location.
\r
285 getItem(dimension1Index: number, ...dimensionNIndexes: number[]): T;
\r
288 * Returns the smallest available index for a given dimension.
\r
289 * @param dimension 1-based dimension (defaults to 1)
\r
291 lbound(dimension?: number): number;
\r
294 * Returns the largest available index for a given dimension.
\r
295 * @param dimension 1-based dimension (defaults to 1)
\r
297 ubound(dimension?: number): number;
\r
300 * Returns a Javascript array with all the elements in the VBArray. If there are multiple dimensions,
\r
301 * each successive dimension is appended to the end of the array.
\r
302 * Example: [[1,2,3],[4,5,6]] becomes [1,2,3,4,5,6]
\r
307 interface VBArrayConstructor {
\r
308 new <T = any>(safeArray: SafeArray<T>): VBArray<T>;
\r
311 declare var VBArray: VBArrayConstructor;
\r
314 * Automation date (VT_DATE)
\r
316 declare class VarDate {
\r
317 private constructor();
\r
318 private VarDate_typekey: VarDate;
\r
321 interface DateConstructor {
\r
322 new (vd: VarDate): Date;
\r
326 getVarDate: () => VarDate;
\r