lib.scripthost.d.ts 9.5 KB

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