Creating Your Own HTAs
Shows how to add a subroutine (named GetServicePack) to an HTA. This is the answer to a Try It Yourself exercise found in the introductory tutorial on creating HTAs.
<head>
<title>Operating System Version</title>
<HTA:APPLICATION
APPLICATIONNAME="Operating System Version"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetOSVersion
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Msgbox objOperatingSystem.Caption & " " & _
objOperatingSystem.Version
Next
End Sub
Sub GetServicePack
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Msgbox objOperatingSystem.ServicePackMajorVersion _
& "." & objOperatingSystem.ServicePackMinorVersion
Next
End Sub
</script>
<body>
<input type="button" value="Operating System" name="run_button" onClick="GetOSVersion">
<input type="button" value="Service Pack" name="service_pack" onClick="GetServicePack">
</body>