1 2 3///////////////////////////// 4/// Windows Script Host APIS 5///////////////////////////// 6 7 8interface ActiveXObject { 9 new (s: string): any; 10} 11declare var ActiveXObject: ActiveXObject; 12 13interface ITextWriter { 14 Write(s: string): void; 15 WriteLine(s: string): void; 16 Close(): void; 17} 18 19interface TextStreamBase { 20 /** 21 * The column number of the current character position in an input stream. 22 */ 23 Column: number; 24 25 /** 26 * The current line number in an input stream. 27 */ 28 Line: number; 29 30 /** 31 * Closes a text stream. 32 * It is not necessary to close standard streams; they close automatically when the process ends. If 33 * you close a standard stream, be aware that any other pointers to that standard stream become invalid. 34 */ 35 Close(): void; 36} 37 38interface TextStreamWriter extends TextStreamBase { 39 /** 40 * Sends a string to an output stream. 41 */ 42 Write(s: string): void; 43 44 /** 45 * Sends a specified number of blank lines (newline characters) to an output stream. 46 */ 47 WriteBlankLines(intLines: number): void; 48 49 /** 50 * Sends a string followed by a newline character to an output stream. 51 */ 52 WriteLine(s: string): void; 53} 54 55interface TextStreamReader extends TextStreamBase { 56 /** 57 * Returns a specified number of characters from an input stream, starting at the current pointer position. 58 * Does not return until the ENTER key is pressed. 59 * Can only be used on a stream in reading mode; causes an error in writing or appending mode. 60 */ 61 Read(characters: number): string; 62 63 /** 64 * Returns all characters from an input stream. 65 * Can only be used on a stream in reading mode; causes an error in writing or appending mode. 66 */ 67 ReadAll(): string; 68 69 /** 70 * Returns an entire line from an input stream. 71 * Although this method extracts the newline character, it does not add it to the returned string. 72 * Can only be used on a stream in reading mode; causes an error in writing or appending mode. 73 */ 74 ReadLine(): string; 75 76 /** 77 * Skips a specified number of characters when reading from an input text stream. 78 * Can only be used on a stream in reading mode; causes an error in writing or appending mode. 79 * @param characters Positive number of characters to skip forward. (Backward skipping is not supported.) 80 */ 81 Skip(characters: number): void; 82 83 /** 84 * Skips the next line when reading from an input text stream. 85 * Can only be used on a stream in reading mode, not writing or appending mode. 86 */ 87 SkipLine(): void; 88 89 /** 90 * Indicates whether the stream pointer position is at the end of a line. 91 */ 92 AtEndOfLine: boolean; 93 94 /** 95 * Indicates whether the stream pointer position is at the end of a stream. 96 */ 97 AtEndOfStream: boolean; 98} 99 100declare var WScript: { 101 /** 102 * Outputs text to either a message box (under WScript.exe) or the command console window followed by 103 * a newline (under CScript.exe). 104 */ 105 Echo(s: any): void; 106 107 /** 108 * Exposes the write-only error output stream for the current script. 109 * Can be accessed only while using CScript.exe. 110 */ 111 StdErr: TextStreamWriter; 112 113 /** 114 * Exposes the write-only output stream for the current script. 115 * Can be accessed only while using CScript.exe. 116 */ 117 StdOut: TextStreamWriter; 118 Arguments: { length: number; Item(n: number): string; }; 119 120 /** 121 * The full path of the currently running script. 122 */ 123 ScriptFullName: string; 124 125 /** 126 * Forces the script to stop immediately, with an optional exit code. 127 */ 128 Quit(exitCode?: number): number; 129 130 /** 131 * The Windows Script Host build version number. 132 */ 133 BuildVersion: number; 134 135 /** 136 * Fully qualified path of the host executable. 137 */ 138 FullName: string; 139 140 /** 141 * Gets/sets the script mode - interactive(true) or batch(false). 142 */ 143 Interactive: boolean; 144 145 /** 146 * The name of the host executable (WScript.exe or CScript.exe). 147 */ 148 Name: string; 149 150 /** 151 * Path of the directory containing the host executable. 152 */ 153 Path: string; 154 155 /** 156 * The filename of the currently running script. 157 */ 158 ScriptName: string; 159 160 /** 161 * Exposes the read-only input stream for the current script. 162 * Can be accessed only while using CScript.exe. 163 */ 164 StdIn: TextStreamReader; 165 166 /** 167 * Windows Script Host version 168 */ 169 Version: string; 170 171 /** 172 * Connects a COM object's event sources to functions named with a given prefix, in the form prefix_event. 173 */ 174 ConnectObject(objEventSource: any, strPrefix: string): void; 175 176 /** 177 * Creates a COM object. 178 * @param strProgiID 179 * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events. 180 */ 181 CreateObject(strProgID: string, strPrefix?: string): any; 182 183 /** 184 * Disconnects a COM object from its event sources. 185 */ 186 DisconnectObject(obj: any): void; 187 188 /** 189 * Retrieves an existing object with the specified ProgID from memory, or creates a new one from a file. 190 * @param strPathname Fully qualified path to the file containing the object persisted to disk. 191 * For objects in memory, pass a zero-length string. 192 * @param strProgID 193 * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events. 194 */ 195 GetObject(strPathname: string, strProgID?: string, strPrefix?: string): any; 196 197 /** 198 * Suspends script execution for a specified length of time, then continues execution. 199 * @param intTime Interval (in milliseconds) to suspend script execution. 200 */ 201 Sleep(intTime: number): void; 202}; 203 204/** 205 * WSH is an alias for WScript under Windows Script Host 206 */ 207declare var WSH: typeof WScript; 208 209/** 210 * Represents an Automation SAFEARRAY 211 */ 212declare class SafeArray<T = any> { 213 private constructor(); 214 private SafeArray_typekey: SafeArray<T>; 215} 216 217/** 218 * Allows enumerating over a COM collection, which may not have indexed item access. 219 */ 220interface Enumerator<T = any> { 221 /** 222 * Returns true if the current item is the last one in the collection, or the collection is empty, 223 * or the current item is undefined. 224 */ 225 atEnd(): boolean; 226 227 /** 228 * Returns the current item in the collection 229 */ 230 item(): T; 231 232 /** 233 * Resets the current item in the collection to the first item. If there are no items in the collection, 234 * the current item is set to undefined. 235 */ 236 moveFirst(): void; 237 238 /** 239 * Moves the current item to the next item in the collection. If the enumerator is at the end of 240 * the collection or the collection is empty, the current item is set to undefined. 241 */ 242 moveNext(): void; 243} 244 245interface EnumeratorConstructor { 246 new <T = any>(safearray: SafeArray<T>): Enumerator<T>; 247 new <T = any>(collection: { Item(index: any): T }): Enumerator<T>; 248 new <T = any>(collection: any): Enumerator<T>; 249} 250 251declare var Enumerator: EnumeratorConstructor; 252 253/** 254 * Enables reading from a COM safe array, which might have an alternate lower bound, or multiple dimensions. 255 */ 256interface VBArray<T = any> { 257 /** 258 * Returns the number of dimensions (1-based). 259 */ 260 dimensions(): number; 261 262 /** 263 * Takes an index for each dimension in the array, and returns the item at the corresponding location. 264 */ 265 getItem(dimension1Index: number, ...dimensionNIndexes: number[]): T; 266 267 /** 268 * Returns the smallest available index for a given dimension. 269 * @param dimension 1-based dimension (defaults to 1) 270 */ 271 lbound(dimension?: number): number; 272 273 /** 274 * Returns the largest available index for a given dimension. 275 * @param dimension 1-based dimension (defaults to 1) 276 */ 277 ubound(dimension?: number): number; 278 279 /** 280 * Returns a Javascript array with all the elements in the VBArray. If there are multiple dimensions, 281 * each successive dimension is appended to the end of the array. 282 * Example: [[1,2,3],[4,5,6]] becomes [1,2,3,4,5,6] 283 */ 284 toArray(): T[]; 285} 286 287interface VBArrayConstructor { 288 new <T = any>(safeArray: SafeArray<T>): VBArray<T>; 289} 290 291declare var VBArray: VBArrayConstructor; 292 293/** 294 * Automation date (VT_DATE) 295 */ 296declare class VarDate { 297 private constructor(); 298 private VarDate_typekey: VarDate; 299} 300 301interface DateConstructor { 302 new (vd: VarDate): Date; 303} 304 305interface Date { 306 getVarDate: () => VarDate; 307} 308