home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _1b73d03d20398fdcd32fa66db9731428 < prev    next >
Encoding:
Text File  |  2004-06-01  |  26.0 KB  |  589 lines

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  
  3. <html>
  4.  
  5. <head>
  6. <title>Rough Guide to Windows Script Host</title>
  7. <link rel="stylesheet" href="../Active.css" type="text/css">
  8. </head>
  9.  
  10. <body>
  11.  
  12. <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EAE2BB">
  13. <tr> 
  14. <td width="57"><a target=_blank href="http://www.ActiveState.com/ActivePerl/">
  15. <img src="../images/activeperl_logo.gif" width="57" height="48" border="0" alt="ActivePerl"></a></td>
  16. <td><div align="center" class="heading">ActivePerl User Guide</div></td>
  17. <td width="112"><a target=_blank  href="http://www.ActiveState.com">
  18. <img src="../images/AS_logo.gif" width="112" height="48" border="0"  alt="ActiveState" /></a></td>
  19. </tr>
  20. <tr>
  21. <td class="lineColour" colspan="3"></td>
  22. </tr>
  23. </table>
  24.  
  25. <h1>Windows Script Host (WSH)</h1>
  26.  
  27. <a name="__index__"></a>
  28. <ul>
  29.   <li><a class="doc" href="#introduction">Windows Script Host (WSH)</a>
  30.     <ul>
  31.       <li><a class="doc" href="#executing">Running a WSH File</a>
  32.       <li><a class="doc" href="#objectmodel">The Object Model</a>
  33.         <ul>
  34.           <li><a class="doc" href="#wscript">The Windows Script Object</a>
  35.           <li><a class="doc" href="#wshshell">The WshShell Object</a>
  36.             <ul>
  37.               <li><a class="doc" href="#shortcut">Creating Shortcuts</a>
  38.               <li><a class="doc" href="#specialfolder">Special Folders</a>
  39.               <li><a class="doc" href="#registry">working with The Registry</a>
  40.               <li><a class="doc" href="#misc">Miscellanous</a>
  41.             </ul>
  42.           <li><a class="doc" href="#network">The WshNetwork Object</a>
  43.         </ul>
  44.       <li><a class="doc" href="#elementref">XML Element Referece</a>
  45.         <ul>
  46.           <li><a class="doc" href="#elemjob"><job></a>
  47.           <li><a class="doc" href="#elemscr"><script></a>
  48.           <li><a class="doc" href="#elemres"><resource></a>
  49.           <li><a class="doc" href="#elemref"><reference></a>
  50.         </ul>
  51.     </ul>
  52.   <li><a class="doc" href="#author and copyright">AUTHOR AND COPYRIGHT</a>
  53. </ul>
  54.  
  55.  
  56. <h2><a name="introduction">Windows Script Host (ASP)</a></h2>
  57. <p>Windows Script Host (WSH) is a scripting host for ActiveX Scripting Engines such
  58. as PerlScript. As a host, WSH enables you to use the scripting language from the
  59. command-line and from within the Windows desktop with the WSH features.</p>
  60.  
  61. <h2><a name="executing">Running a WSH File</a></h2>
  62. <p>In order to execute a WSH-file, use one of two executable files depending on
  63. your needs: WScript.exe for Windows desktop files and CScript.exe is for
  64. command-line scripts. You can set the behavior and appearance of these executed
  65. scripts by running the executable without providing a file; if so, WScript will
  66. display a properties page that you can modify, and CScript will show the
  67. available switches. At work, WSH enables you to use more than one scripting
  68. engine in the same file, include typelibraries, and run more than a single job
  69. from one file to name a few.</p>
  70.  
  71. <h2><a name="objectmodel">The Object Model</a></h2>
  72. <p>Implemented as an object-model, WSH provides a simple interface for its tasks.
  73. As you author, the WSH file uses XML as its markup for separating the elements.
  74. Let's look at a simple WSH file that prints "Hello World!".
  75. <blockquote style="MARGIN-RIGHT: 0px">
  76.   <code><Job ID="HelloWorld"><br>
  77.   <script language=PerlScript><br>
  78.       $WScript->Echo("Hello World!");<br>
  79.   </script><br>
  80.   </Job></code>
  81. </blockquote>
  82. <p>The XML Job-elements encloses the ID of the Job that is run, and the script
  83. elements define PerlScript as the script language to use. You will experience
  84. different results depending if you execute this from the command-line or from
  85. the windows desktop. The first instance will print text to the screen, but the
  86. Windows desktop will pop up a messagebox with "Hello World!" Next,
  87. let's look at what the WScript object has to offer.</p>
  88.  
  89. <h2><a name="wscript">The Windows Script Object</a></h2>
  90. <p>The WScript object is a built-in object; therefore, you do not need to create a
  91. specific instance of it within your WSH. On the contrary, the object in place is
  92. used to create instances of most other objects exposed through the WSH
  93. programming interface.</p>
  94.  
  95. <p>The <code>CreateObject</code> method will create an instance of a given object.
  96. In the following example, we'll see how an ADO Connection object is easily
  97. created within WSH.
  98. <blockquote style="MARGIN-RIGHT: 0px">
  99.   <code><Job ID="ADOSample1"><br>
  100.   <script language=PerlScript><br>
  101.       $conn = $WScript->CreateObject('ADODB.Connection');<br>
  102.       $conn->Open('ADOSamples');<br>
  103.   <br>
  104.       if($conn->{State} == 1) {<br>
  105.           $WScript->Echo("Connection
  106.   Successful!")<br>
  107.       }<br>
  108.       else {<br>
  109.           $WScript->Echo("Connection
  110.   Failed ...");<br>
  111.       }<br>
  112.   </script><br>
  113.   </Job></code>
  114. </blockquote>
  115.  
  116. <p>In addition to the above, you can specify a second parameter in the call to <code>CreateObject</code>.
  117. This parameter contains a string which defines a prefix that you specify. By
  118. doing so, the object's outgoing interface is connected and any time an event is
  119. fired from the object, you can intercept it within the WSH file. For example, in
  120. the ADO connection object, there are a number of events. Sparing the details, <code>WillConnect</code>
  121. is called before a connection starts, and <code>Connectcomplete</code> is called
  122. after a connection has been started. They can be easily intercepted within the
  123. WSH file.
  124. <blockquote style="MARGIN-RIGHT: 0px">
  125.   <code><Job ID="Test"><br>
  126.   <script language=PerlScript><br>
  127.       $conn=$WScript->CreateObject('ADODB.Connection', 'MyWSH_');<br>
  128.       $conn->Open('ADOSamples');<br>
  129.   <br>
  130.       if($conn->{State} == 1) {<br>
  131.           $WScript->Echo("Connection
  132.   Successful!")<br>
  133.       }<br>
  134.       else {<br>
  135.           $WScript->Echo("Connection
  136.   Failed ...");<br>
  137.       }<br>
  138.   <br>
  139.       sub MyWSH_ConnectComplete {<br>
  140.           $WScript->Echo("ConnectComplete
  141.   was fired ... ");<br>
  142.       }<br>
  143.   <br>
  144.       sub MyWSH_WillConnect {<br>
  145.           $WScript->Echo("WillConnect
  146.   was fired ... ");<br>
  147.       }<br>
  148.   </script><br>
  149.   </Job></code>
  150. </blockquote>
  151.  
  152. <p>For the same result as above, you can use the <code>ConnectObject</code>-method
  153. whose syntax is <code>$WScript->ConnectObject(Object, Prefix);</code>. The
  154. method <code>$WScript->DisconnectObject(Object);</code> will disconnect its
  155. event handling provided that the object is connected. Some other methods are as
  156. follows: <code>$Wscript->Echo(1, 2, 3, n);</code> Print text to the standard
  157. output defined by WSH. Separating the arguments cause only a space to separate
  158. the items in a desktop environment and a newline to separate the items in a
  159. command-line scenario.<br>
  160. <br>
  161. <blockquote style="MARGIN-RIGHT: 0px">
  162.   <code>$WScript->GetObject(Pathname [,ProgID] [,Prefix]);</code>
  163. </blockquote>
  164. <p>Retrieves an Automation object from a file or an object specified by the
  165. strProgID parameter.<br>
  166. <br>
  167. <blockquote style="MARGIN-RIGHT: 0px">
  168.   <code>$WScript->Quit([$int_errorcode]);</code>
  169. </blockquote>
  170. <p>Quit and process and optionally provide an integer which represents an error
  171. code.<br>
  172. <br>
  173. <blockquote style="MARGIN-RIGHT: 0px">
  174.   <code>$WScript->Sleep($int_milliseconds);</code>
  175. </blockquote>
  176. <p>Places the script process into an inactive state for the number of milliseconds
  177. specified and then continues execution.<br>
  178. <br>
  179. <p>And its properties are:
  180. <blockquote style="MARGIN-RIGHT: 0px">
  181.   <code>$WScript->{Application};</code>
  182. </blockquote>
  183. <p>Provides the IDispatch interface on the WScript object<br>
  184. <br>
  185. <blockquote style="MARGIN-RIGHT: 0px">
  186.   <code>$WScript->{Arguments};</code>
  187. </blockquote>
  188. <p>Returns a pointer to the WshArguments collection or identifies arguments for the
  189. shortcut to the collection.<br>
  190. <br>
  191. <blockquote style="MARGIN-RIGHT: 0px">
  192.   <code>$WScript->{Fullname};</code>
  193. </blockquote>
  194. <p>Returns a string containing the full path to the host executable file or
  195. shortcut object.<br>
  196. <br>
  197. <blockquote style="MARGIN-RIGHT: 0px">
  198.   <code>$WScript->{Name};</code>
  199. </blockquote>
  200. <p>Returns a string containing the friendly name of the WScript object.<br>
  201. <br>
  202. <blockquote style="MARGIN-RIGHT: 0px">
  203.   <code>$WScript->{Path};</code>
  204. </blockquote>
  205. <p>Provides a string containing the name of the directory where WScript.exe or
  206. CScript.exe resides.<br>
  207. <br>
  208. <blockquote style="MARGIN-RIGHT: 0px">
  209.   <code>$WScript->{Scriptfullname};</code>
  210. </blockquote>
  211. <p>Provides the full path to the script currently being run.<br>
  212. <br>
  213. <blockquote style="MARGIN-RIGHT: 0px">
  214.   <code>$WScript->{Scriptname};</code>
  215. </blockquote>
  216. <p>Provides the file name of the script currently being run.<br>
  217. <br>
  218. <blockquote style="MARGIN-RIGHT: 0px">
  219.   <code>$WScript->{StdError};</code>
  220. </blockquote>
  221. <p>Exposes the write-only error output stream for the current script. Only
  222. applicable with CScript command-line WSH files.<br>
  223. <br>
  224. <blockquote style="MARGIN-RIGHT: 0px">
  225.   <code>$WScript->{StdIn};</code>
  226. </blockquote>
  227. <p>Exposes the read-only input stream for the current script. CScript only.<br>
  228. <br>
  229. <blockquote style="MARGIN-RIGHT: 0px">
  230.   <code>WScript->{StdOut};</code>
  231. </blockquote>
  232. <p>Exposes the write-only output stream for the current script. CScript only.<br>
  233. <br>
  234. <blockquote style="MARGIN-RIGHT: 0px">
  235.   <code>$WScript->{Version};</code>
  236. </blockquote>
  237. <p>Returns the version of Microsoft Windows Script Host.<br>
  238. <p>On a final note, if you are using Cscript.exe and passing arguments to the file,
  239. you can read the arguments as follows:
  240. <blockquote style="MARGIN-RIGHT: 0px">
  241.   <code><Job ID="args"><br>
  242.   <script language=PerlScript><br>
  243.       $arg = $WScript->{Arguments};<br>
  244.   <br>
  245.       $countArgs = $arg->{Count};<br>
  246.   <br>
  247.       for($i=0; $i<$countArgs; $i++) {<br>
  248.           $WScript->Echo($arg->Item($i));<br>
  249.       }<br>
  250.   </script><br>
  251.   </job></code>
  252. </blockquote>
  253.  
  254. <h2><a name="wshshell">The WShShell Object</a></h2>
  255. <p>The WshShell object must be instantiated by the WScript object.
  256. <blockquote style="MARGIN-RIGHT: 0px">
  257.   <code>$WshShell = $WScript->CreateObject("WScript.Shell")</code>
  258. </blockquote>
  259. <p>An interesting method of the WshShell object is the ability to activate an
  260. application window and putting it in focus. This is done by calling AppActivate
  261. either with the title in the title bar of the running application window as a
  262. parameter or by using the task ID as a parameter.
  263. <blockquote style="MARGIN-RIGHT: 0px">
  264.   <code><Job Id="WshShell"><br>
  265.   <script language=PerlScript><br>
  266.       $WshShell = $WScript->CreateObject("WScript.Shell");<br>
  267.       $WshShell->Run("notepad");<br>
  268.       $WshShell->AppActivate("Untitled -
  269.   Notepad");<br>
  270.   <br>
  271.       my $message = "Hello from PerlScript!\n";<br>
  272.   <br>
  273.       for($i=0; $i < length($message); $i++) {<br>
  274.           $char = substr($message, $i,
  275.   1);<br>
  276.           $WScript->Sleep(100);<br>
  277.           $WshShell->SendKeys($char);<br>
  278.       }<br>
  279.   </script><br>
  280.   </job></code>
  281. </blockquote>
  282. <p>The <code>SendKeys</code>-method simply sends keystrokes to the active windows.
  283. <p>The <code>Run</code> method is a little more flexible.
  284. <blockquote style="MARGIN-RIGHT: 0px">
  285.   <code>$WshShell->Run(Command, [WindowStyle], [WaitOnReturn]);</code>
  286. </blockquote>
  287. <p>The WindowStyle can be an integer between 0 through 10, and WaitOnReturn is a
  288. boolean value or 1 (TRUE) or 0 (FALSE). FALSE is the default value it means that
  289. an immeditate return to script execution contrary to waiting for the process to
  290. end is preferable. It also returns an error code of zero while TRUE returns any
  291. error code generated by the active application.
  292.  
  293. <h3><a name="shortcut">Creating Shortcuts</a></h3>
  294. <p>In addition, you can create shortcuts. Either you create a dekstop shortcut or a
  295. URL shortcul. The method call <code>CreateShortcut($path_or_url)</code> returns
  296. an object reference to a <code>WshShortcut</code>-object. Keep in mind that a
  297. dekstop shortcut has tbe extension .lnk and an URL shortcul has the file
  298. extension .url. In the latter case, a WshURLShortcut object is returned.</p>
  299.  
  300. <p>With the WshShortcut-object, one method exists, so it is mainly properties
  301. regarding the shortcut that you need to set. The <code>Description</code>-property
  302. contains a string describing the shortcut, <code>Fullname</code> returns the
  303. full path to the host executable, <code>Hotkey</code> allows for combinations
  304. such as "ALT+CTRL+X" as hotkeys for shortcuts on the Windows dekstop
  305. or windows startmenu, <code>IconLocation</code> is a property that you set to
  306. "Path, index" to provide the Icon location of the shortcut. In
  307. addition, use the <code>TargetPath</code>-property to set the path to the
  308. executable file pointed to by the shortcut, <code>WindowStyle</code> can be set
  309. to either 1, 3, or 7 for the shortcut object, and <code>WorkingDirectory</code>
  310. defines the directory in which the shortcut should start. If you are
  311. shortcutting a URL, you have only the <code>Fullname</code> and <code>TargetPath</code>
  312. properties where the latter one is a URL. All shortcut objects are final when
  313. you call the <code>Save</code> method.</p>
  314.  
  315. <h3><a name="specialfolder">Special Folders</a></h3>
  316. <p>The WshShell object can also return a WshSpecialFolders object which contains
  317. paths to shell folders such as the desktop, start menu, and personal documents.
  318. <blockquote style="MARGIN-RIGHT: 0px">
  319.   <code><Job Id="SpecialFolder"><br>
  320.   <script language=PerlScript><br>
  321.       $WshShell = $WScript->CreateObject("WScript.Shell");<br>
  322.       $numFolders = $WshShell->SpecialFolders->{Count};<br>
  323.       $title = "PerlScript & WSH Example";<br>
  324.       $style = 1;<br>
  325.   <br>
  326.       for($i=0; $i<$numFolders; $i++) {<br>
  327.           $ok_or_cancel = $WshShell->Popup(<br>
  328.               $WshShell->SpecialFolders($i),<br>
  329.               undef,<br>
  330.               $title,<br>
  331.               $style);<br>
  332.   <br>
  333.           exit if ($ok_or_cancel == 2);<br>
  334.       }<br>
  335.   </script><br>
  336.   </job></code>
  337. </blockquote>
  338.  
  339. <h3><a name="registry">Working With the Registry</a></h3>
  340. <p>The WshShell object provides functionality for working with the registry. The
  341. three methods for this are: <code>RegRead</code>, <code>RegWrite</code>, and <code>RegDelete</code>.
  342. Simply provide either method with a string such as the short form HKCU\ScriptEngine\Val
  343. or longer variant HKEY_CURRENT_USER\ScrtipeEngine\Val. Notice that a key is
  344. returned if the last character is a backslash, and a value is returned if no
  345. backslash is at the end. The <code>RegRead</code> method supports the following data types:
  346. <blockquote style="MARGIN-RIGHT: 0px">
  347.   <ul>
  348.     <li>REG_SZ
  349.     <li>REG_EXPAND_SZ
  350.     <li>REG_DWORD
  351.     <li>REG_BINARY
  352.     <li>REG_MULTI_SZ
  353.   </ul>
  354. </blockquote>
  355. <p><code>RegWrite</code> requires a few extra parameters:
  356. <blockquote style="MARGIN-RIGHT: 0px">
  357.   <code>$WshShell->RegWrite(Name, Value [,Type]);</code>
  358. </blockquote>
  359. <p>The name is a fully qualified string such as HKCU\ScriptEngine\Val where the
  360. same rules apply for key and value as previously mentioned. The Type-parameter
  361. is optional, but if used, it must be one of the following data types:
  362. <blockquote style="MARGIN-RIGHT: 0px">
  363.   <ul>
  364.     <li>REG_SZ
  365.     <li>REG_EXPAND_SZ
  366.     <li>REG_DWORD
  367.     <li>REG_BINARY
  368.   </ul>
  369. </blockquote>
  370.  
  371. <h3><a name="misc">Miscellanous</a></h3>
  372. <p>Expands the requested environment variable from the running process:
  373. <blockquote style="MARGIN-RIGHT: 0px">
  374.   <code>$WshShell->ExpandEnvironmentStrings($string);</code>
  375. </blockquote>
  376. <p>In addition, log an event in the NT event log or WSH.log (Windows 9x) file
  377. using:
  378. <blockquote style="MARGIN-RIGHT: 0px">
  379.   <code>$WshShell->LogEvent(Type, Message [,Target]);</code>
  380. </blockquote>
  381. <p>Target is the name of the system on NT, thus only applicable on NT. The Type of
  382. event is either
  383. <blockquote style="MARGIN-RIGHT: 0px">
  384.   <ul>
  385.     <li>0 (SUCCESS)
  386.     <li>1 (ERROR)
  387.     <li>2 (WARNING)
  388.     <li>4 (INFORMATION),
  389.     <li>8 (AUDIT_SUCCESS)
  390.     <li>16 (AUDIT_FAILURE)
  391.   </ul>
  392. </blockquote>
  393. <p>This method returns a boolean value indicating success or failure. Another
  394. method is Popup, which sends a Windows messagebox up on the screen.
  395. <blockquote style="MARGIN-RIGHT: 0px">
  396.   <code>$retval = $WshShell->Popup(Text, [SecondsWait], [Title], [Type]);</code>
  397. </blockquote>
  398. <p>The method allows you to define the text to pop up, alternatively seconds to
  399. wait before closing window, the title of the window, and lastly the type of
  400. buttons available in the window. They can be:
  401. <blockquote style="MARGIN-RIGHT: 0px">
  402.   <ul>
  403.     <li>0 (Ok)
  404.     <li>1 (Ok and Cancel)
  405.     <li>2 (Abort, Retry, and Ignore)
  406.     <li>3 (Yes, No, and Cancel)
  407.     <li>4 (Yes and No)
  408.     <li>5 (Retry and Cancel)
  409.   </ul>
  410. </blockquote>
  411. <p>The value that you choose can also be combined with an icon:
  412. <blockquote style="MARGIN-RIGHT: 0px">
  413.   <ul>
  414.     <li>16 (Stop Mark)
  415.     <li>32 (Question Mark)
  416.     <li>48 (Exclamation Mark)
  417.     <li>64 (Information Mark)
  418.   </ul>
  419. </blockquote>
  420. <p>The return values returned to <code>$retval</code> indicates which button was
  421. pressed. The value will be one of the following:
  422. <blockquote style="MARGIN-RIGHT: 0px">
  423.   <ul>
  424.     <li>1 (OK)
  425.     <li>2 (Cancel)
  426.     <li>3 (Abort)
  427.     <li>4 (Retry)
  428.     <li>5 (Ignore)
  429.     <li>6 (Yes)
  430.     <li>7 (No)
  431.   </ul>
  432. </blockquote>
  433.  
  434. <h2><a name="network">The WshNetwork Object</a></h2>
  435. <p>The WshNetwork object exposes some network functionality. To begin:
  436. <blockquote style="MARGIN-RIGHT: 0px">
  437.   <code>$WshNetwork->AddPrinterConnection($LocalName, $RemoteName[,$UpdateProfile][,$User][,$Password]);</code>
  438. </blockquote>
  439. <p>User and password are two parameters with given meaning. Localname
  440. and Remotename are the names of the printer resource. Set UpdateProfile to TRUE
  441. for storing this mapping in the user profile. Next, AddWindowsPrinterConnection()
  442. adds a printer just as you would add one using the control panel. On Windows
  443. NT/2000 the only parameter you need to call this method with is the path to the
  444. printer while windows 9x requires you to specify the driver to use, and
  445. optionally specify which port to which it is connected. In the last event, the
  446. syntax is:
  447. <blockquote style="MARGIN-RIGHT: 0px">
  448.   <code>$WshNetwork->AddWindowsPrinterConnection($PrinterPath, $DriverName[,$Port])</code>
  449. </blockquote>
  450. <p>As easily as adding a printer, you can remove a printer. Simply do
  451. <blockquote style="MARGIN-RIGHT: 0px">
  452.   <code>$WshNetwork->RemovePrinterConnection($Name, [$Force], [$UpdateProfile]);</code>
  453. </blockquote>
  454. <p>If you set $Force to TRUE (1), it will remove the connection regardless if it is
  455. being used, and setting $UpdateProfile to true will remove any user profile
  456. mapping.<br>
  457. <br>
  458. <p>If you're happy with your printers, you can set one of the printer as your
  459. default printer by a quick call:
  460. <blockquote style="MARGIN-RIGHT: 0px">
  461.   <code>$WshNetwork->SetDefaultPrinter($PrinterName);</code>
  462. </blockquote>
  463. <p>To return a collection of all your printers, call:
  464. <blockquote style="MARGIN-RIGHT: 0px">
  465.   <code>$Printers = $WshNetwork->EnumPrinterConnections();</code>
  466. </blockquote>
  467. <p>Then use the Count-property to retrieve the number of items in the $Printers
  468. collection object.<br>
  469. <br>
  470. <p>When you want to map a drive to a network share, you can use the MapNetworkDrive
  471. method.
  472. <blockquote style="MARGIN-RIGHT: 0px">
  473.   <code>$WshNetwork->MapNetworkDrive($LocalName, $RemoteName,
  474.   [$UpdateProfile], [$User], [$Password]);</code>
  475. </blockquote>
  476. <p>For example:
  477. <blockquote style="MARGIN-RIGHT: 0px">
  478.   <code>$WshNetwork->MapNetworkDrive('C:\', '\\MyComputerServer\\ShareHere);</code>
  479. </blockquote>
  480. <p>Remove a network drive using the now familiar syntax
  481. <blockquote style="MARGIN-RIGHT: 0px">
  482.   <code>$WshNetwork->RemoveNetworkDrive($Name, [$Force], [$UpdateProfile])</code>
  483. </blockquote>
  484. <p>or enumerate the network drives as:
  485. <blockquote style="MARGIN-RIGHT: 0px">
  486.   <code>$Drives = $WshNetwork->EnumNetworkDrive();</code>
  487. </blockquote>
  488. <p>The three properties of the network object are ComputerName, UserName, and
  489. UserDomain.</p>
  490.  
  491. <h2><a name="elementref">XML Element Reference</a></h2>
  492. <p>Like Windows Script Components, the Windows Script Host has a set of XML
  493. elements that can be deployed. For a basic understanding of how they are used,
  494. please refer to the section about Windows Script Components.</p>
  495.  
  496. <h3><a name="elemjob">The Job Element</a></h3>
  497. <p>The Job element is used to define the beginning and the end of the components.
  498. It encapsulates all other tags. Should your WSH file contain more than one job,
  499. encapsulate them within a <package> element. When declaring jobs, the ID
  500. attribute is optional.</p>
  501. <p>Syntax:
  502. <blockquote>
  503.   <code><Job [id=JobID]></code>
  504. </blockquote>
  505. <p>For example:
  506. <blockquote>
  507.   <code><package><br>
  508.       <Job id="PrintOutput"><br>
  509.       </Job><br>
  510.       <Job id="ReadInput"><br>
  511.       </Job><br>
  512.   </package></code>
  513. </blockquote>
  514. <p>You can also set a boolean value of true (1) or false (0) for error checking or
  515. debugging by using the additional tag
  516. <blockquote style="MARGIN-RIGHT: 0px">
  517.   <code><? job error="true" debug="true" ?></code>
  518. </blockquote>
  519.  
  520. <h3><a name="elemscr">The Script Element</a></h3>
  521. <p>The script element lets you define the scripting language to use, and then with
  522. its closing-tag functions as delimiters for the script code.<br>
  523. <p>Syntax:
  524. <blockquote>
  525.   <code><script language="languageName"> code </script></code>
  526. </blockquote>
  527. <p>For example.
  528. <blockquote>
  529.   <code><?XML version="1.0"?><br>
  530.   <job><br>
  531.   ...<br>
  532.   <script language="PerlScriptt"><br>
  533.   <![CDATA[<br>
  534.       sub ReturnValue {<br>
  535.       #<br>
  536.       # Perl code here<br>
  537.       #<br>
  538.       }<br>
  539.   ]]><br>
  540.   </script><br>
  541.   </job></code>
  542. </blockquote>
  543.  
  544. <h3><a name="elemres">The Resource Element</a></h3>
  545. <p>The resource element is a placeholder for strings or numeric data that should be
  546. separate from the script commands yet may be used within the script.</p>
  547. <p>Syntax:
  548. <blockquote>
  549.   <code><resource id="resourceID"> text or number to represent
  550.   resource goes here </resource></code>
  551. </blockquote>
  552. <p>You use the <code>getResource(resourceID)</code> to retrieve the contents of the
  553. resource specified in the resourceID parameter.</p>
  554.  
  555. <h3><a name="elemref">The Reference Element</a></h3>
  556. <p>You can import external type libraries by using the reference element. By
  557. importing a type library, you will be able to naturally access the constants
  558. that belongs to it, too.</p>
  559. <p>Syntax:
  560. <blockquote>
  561.   <code><reference [object="progID" | guid="typelibGUID"]
  562.   [version="versionNo"] /></code>
  563. </blockquote>
  564.  
  565. <h2><a name="author and copyright">AUTHOR AND COPYRIGHT</a></h2>
  566. <p>Written document copyright (c) 2000 Tobias Martinsson. All rights reserved.</p>
  567. <p>When included as part of the Standard Version of Perl, or as part of its
  568. complete documentation whether printed or otherwise, this work may be
  569. distributed only under the terms of Perl's Artistic License. Any distribution of
  570. this file or derivatives thereof <i>outside</i> of that package require that
  571. special arrangements be made with copyright holder.</p>
  572. <p>Irrespective of its distribution, all code examples in this file are hereby
  573. placed into the public domain. You are permitted and encouraged to use this code
  574. in your own programs for fun or for profit as you see fit. A simple comment in
  575. the code giving credit would be courteous but is not required.</p>
  576. <p>Windows Script Host is copyright (c) 1991-2000 Microsoft Corporation. All
  577. Rights Reserved.</p>
  578. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  579.   <tr>
  580.     <td class="block" valign="MIDDLE" width="100%" bgcolor="#cccccc"><strong>
  581.       <p class="block"> Rough Guide to Windows Script Host</p>
  582.       </strong></td>
  583.   </tr>
  584. </table>
  585.  
  586. </body>
  587.  
  588. </html>
  589.