Browse DevX
Sign up for e-mail newsletters from DevX


How To Launch CDs with HTML Applications : Page 3

Use HTML Application (HTA) files to provide an impressive and functional CD launcher for your applications.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Checking for the .NET framework is easy, because the navigator.UserAgent property indicates whether it is installed or not.
The HTA file displays your user interface (see Figure 1) and contains the script to launch your application's setup program. Depending on your application needs, you may wish to launch one of several different types of setup program, as shown in the following sections.

1. Launching a Windows Installer (MSI) Setup
Launching an MSI setup package is very straightforward:

set msi = CreateObject( "WindowsInstaller.Installer" ) msi.InstallProduct("setup.msi") set msi = nothing

2. Launching an EXE File
If you have a setup.exe, rather than a Windows Installer (MSI) file, you can launch it using the Wscript.Shell object.

set objShell = CreateObject( "WScript.Shell" ) lngReturn = objShell.Run ("setup.exe", 1, 1) set objShell = Nothing

Table 1 shows the parameters for the Wscript.Shell Run method:
CommandThe file to run
WindowStyleSets the window style of the program being run. In this case, use the value 1, which activates the window in its default position and size.
Wait on return1 or 0. In this case, we wait for the program to return so we can check the return value.
Table 1: Parameters for the WScript.Shell Run method.

If you have documentation on the possible return values from your setup program, you should check the return value and provide feedback to your users. The sample application has code to provide error feedback for common Windows Installer errors.

3. Checking for the .NET Framework
Checking for the .NET framework is easy, because the navigator.UserAgent property indicates whether it is installed or not. The UserAgent string looks similar to:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)

Heres a code fragment that checks for the .NET framework:

Const DOTNETFRAMEWORK_IDENTIFIER = ".NET CLR" for each strValue in _ split(window.navigator.userAgent, ";") if Instr(1, strValue, DOTNETFRAMEWORK_IDENTIFIER, _ 1) > 0 then ' Framework is installed - show version ' Strip the '.NET CLR' part off intVersionStartIndex = _ len(strValue) - _ (Instr(1, DOTNETFRAMEWORK_IDENTIFIER, _ strValue, 1) + _ Len(DOTNETFRAMEWORK_IDENTIFIER)+1) strFrameworkVersion = right(strValue, _ intVersionStartIndex - 1) ' Get rid of the trailing bracket strFrameworkVersion = _ replace(strFrameworkVersion, ")", "") dotNetFrameworkDetect.innerText = _ ".NET Framework version " & _ strFrameworkVersion & " detected." else ' Framework is not installed dotNetFrameworkDetect.innerHTML = _ "The .NET Framework was not detected. " & _ "You cannot install " & _ "this product until you install the " & _ ".NET Framework. " & _ "<A HREF='http://msdn.microsoft.com/" & _ "downloads/default.asp?url=" & _ "/downloads/sample.asp?url=/" & _ "msdn-files/027/001/829/" & _ "msdncompositedoc.xml'>Click here</A> " & _ "to install the .NET framework now." blnComponentsFoundOK = False end if next

4. Reading the Registry
Sometimes, you need to know what software the user already has installed. One way to do that is to check for the presence of a required ProgID from that application in the registry. The sample application contains code to check for Microsoft Word 2000 by looking in the HKEY_CLASSES_ROOT registry hive for a component with a ProgID of Word.Application.9. You would need to adjust the ProgID appropriately for your own application to look for other installed software. Note that the presence of the ProgID key in the registry does not guarantee that the program you're checking for actually runs on the target system, just that it probably was installed at some point.

set wscript = CreateObject("WScript.Shell") if wscript.regRead _ ("HKCR\Word.Application.9\clsid\") <> "" then msWordDetect.InnerText = "Word 2000 detected." else msWordDetect.InnerText = _ "Word 2000 was not detected. You cannot install this product." end if set wscript = Nothing

Such code is also useful for checking to see if your application is already installed. If it is, you can suppress the "Install Now" link, or display a message to the user.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date