Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Although you can control Internet Explorer from a separate script, you will have to include code to repeatedly ensure that the browser is still running. If you do not, you will encounter problems such as:
Embedding the script code inside a Web page enables you to overcome these problems. When you embed the code, the Web page and the script are linked together; closing the Web page will also terminate the script. However, this introduces a new set of problems. Because Internet Explorer is designed for use over the Internet, it has a number of built-in security precautions that prevent Web sites from harming the local computer in any way. For example, if you include Windows Management Instrumentation (WMI) or another ActiveX® control in a Web page, a message box similar to the one shown in Figure 17.3 will appear when the script is run.
Figure 17.3 Unsafe for Scripting Message Box
Unsafe for Scripting Message Box
In turn, the script will suspend itself until you click Yes. This means you cannot create a Web page that can refresh itself (for example, a Web page that periodically updates the status of all the printers on a print server). Each time the page queries the WMI service, the "unsafe for scripting" message box will appear and the script will pause until you click Yes.
One way to work around the security issues inherent in Internet Explorer is to embed your script within a hypertext application (HTA) rather than an HTML file. In its simplest form, an HTA is nothing but a Web page with the .hta file name extension rather than the .htm file name extension. In fact, you can convert any Web page to an HTA just by changing the file name extension.
However, HTAs run in a different process (Mshta.exe) than do HTML files. This allows HTAs to bypass Internet Explorer security. (Of course, HTAs still respect such things as operating system security and the NTFS file system security.) HTAs are fully trusted applications, meaning that you will not receive any security warnings when using objects such as WMI or the FileSystemObject.
Although HTAs respond to the same commands that can be issued to an instance of Internet Explorer, a number of additional attributes are available through the HTA object model. Several of these attributes are listed in Table 17.4.
Table 17.4 HTA Object Model
Attribute | Description |
---|---|
ApplicationName | Sets the name of the HTA. |
Border | Sets the type of border used for the HTA window. Values include: Thick. Creates a resizeable window. Thin. Creates a window that cannot be resized. |
BorderStyle | Sets the style of the content border in the HTA window. Values are: Normal. Standard Windows border style. This is the default value. Raised. Raised three-dimensional border. Sunken. Sunken three-dimensional border. Complex. Combines sunken and raised styles. Static. Three-dimensional border typically used for windows that do not allow user input. |
Caption | Yes/No value specifying whether the HTA displays a title bar. The default value is Yes. |
Icon | Sets the path name of the icon that appears in the upper-left corner of the HTA window. The icon can be either a .ico or a .bmp file. If not specified, a generic application icon is used. |
ID | Sets the identifier for the <HTA:Application> tag. This property is required if you need to write a script that returns the attributes of the HTA. |
MaximizeButton | Yes/No value specifying whether the HTA displays a Maximize button in the title bar. The default value is Yes. |
MinimizeButton | Yes/No value specifying whether the HTA displays a Minimize button in the title bar. The default value is Yes. |
ShowInTaskbar | Yes/No value specifying whether the HTA is shown in the Windows taskbar. Regardless of the value set for this property, the HTA will always appear in the list of applications that are accessible when you press ALT+TAB. The default value is Yes. |
SingleInstance | Yes/No value specifying whether more than one instance of this HTA can be active at any given time. For this property to take effect, you must also specify the ApplicationName attribute. The default value is Yes. |
SysMenu | Yes/No value specifying whether the HTA displays the System menu in the title bar. The System menu is displayed in the upper-left corner of the HTA window and provides access to menu items such as Minimize, Maximize, Restore, and Close. The default value is Yes. |
WindowsState | Sets the initial size of the HTA window. Values are: Normal Minimize Maximize |
HTML applications require no special coding; you can create an HTA simply by changing the .htm file extension of a Web page to .hta. However, by adding the <HTA:Application> tag to the Web page code, you can gain additional control over how the HTA will be displayed on the screen and which elements of the user interface will be available. To configure any of these elements, include the <HTA:Application> tag and the appropriate elements within the Web page <HEAD> tag.
For example, the following code snippet prevents the HTA from being displayed in the taskbar:
<HTA:Application ShowInTaskbar = No >
Listing 17.9 contains HTML tags for creating a sample HTA file. Type this code into a text editor, and then save it with the .hta file name extension.
To create an HTA file, you must:
Listing 17.9 Creating an HTA File
|
|
A sample HTA that displays service information is shown in Listing 17.10. In this script, the code to retrieve service information and to write that data to the browser window is included in a window_onLoad procedure. This procedure automatically runs anytime the Web page is loaded. As a result, service information will be displayed anytime you start (or refresh) the HTA.
Listing 17.10 Using an HTA to Display Service Information
|
|
Send us your feedback | « Previous | Next » |