home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: libHTA.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: The Shared Computer Toolkit for Windows XP Common HTA Framework
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes:
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared
- ' ~~~
- Option Explicit
-
- ' ~~~
- ' ~~~ Declare global variables and constants
- ' ~~~
- Dim sTitle, bDomainMember, bProcessing
- bProcessing = True
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Main()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Initialize the framework
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub Main()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Dim bOK
- bOK = True
-
- ' ~~~ Call the InitialiseAllObjects method
- InitialiseAllObjects()
-
- ' ~~~ Sets DEBUG using registry value from this point on
- DEBUG = RegRead(TOOLKITKEY & "SCTDebug")
-
- If DEBUG = "1" Then
- DEBUG = True
- Else
- DEBUG = False
- End If
-
- IsAppRunningTwice()
-
- ' ~~~ Resize the tool first, if the tool should be
- Call ResizeMe()
-
- ' ~~~ Disable the body on load
- Call BodyDisable(True)
-
- ' ~~~ Set up the screen, load controls and pages
- Call Setup()
-
- ' ~~~ Prereq checks
- If document.all("resAdminOnly").innerHTML = "YES" Then
- bOK = IsAdministrator(True)
- End If
-
- If bOK and document.all("resWGAOnly").innerHTML = "YES" Then
- If CheckWGA(True) = False Then bOK = False
- End If
-
- If InSafeMode(True) Then bOK = False
-
- ' ~~~ If ok continue
- If bOK Then
-
- ' ~~~ Call the tool initalization function
- Call Init()
-
- ' ~~~ Call the domain warning method
- Call ShowDomainWarning()
-
- ' ~~~ Call the tool load function
- Call Load()
- bProcessing = False
- Else
- bProcessing = False
- Call BodyDisable(False)
- Self.Close()
- End If
- End Sub
-
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Check for .HTA running
- ' ~~~ ------------------------------------------------------------------------------
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: IsAppRunningTwice()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Check to see if .HTA is running more than once.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub IsAppRunningTwice()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Dim iCount, colProcesses, oProcess, sAppName
-
-
- sAppName = lCase(GetAppName & ".hta")
-
- Set colProcesses = oWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name='MSHTA.EXE'")
-
- iCount = 0
-
- For Each oProcess in colProcesses
- If Left(Right(LCase(oProcess.CommandLine), len(sAppName) + 2), len(sAppName)) = sAppName Then
- iCount = iCount + 1
- If iCount > 1 Then
- bProcessing = False
- Window.Close
- exit sub
- End If
- End If
- Next
-
- End Sub
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Screen setup and handling
- ' ~~~ ------------------------------------------------------------------------------
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: ResizeMe()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Resize the HTA
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub ResizeMe()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- If oImagine.Border <> "thick" Then
- Window.resizeTo oDiv.offsetLeft + oDiv.offsetWidth + 15, oFooter.offsetTop + oFooter.offsetHeight + 35
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Setup()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Sets up the hta
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub Setup()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ' set the titles
- document.title = appTitle.innerHTML
- sTitle = appTitle.innerHTML
- title.Title = L_sToolkitTitle_TEXT
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: ShowDomainWarning()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Checks if the computer is a member of a domain
- ' *** If it is, the domain warning message is shown and the function
- ' *** returns false; otherwise the function returns true
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function ShowDomainWarning()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim bchkDomainWarning
- bDomainMember = DomainMember()
- bchkDomainWarning = False
- If resDomainWarning.innerHTML = "YES" Then
- If bDomainMember and RegRead(TOOLKITKEY & "ShowDomainWarning") = "1" Then
- ShowDomainWarning = True
- ' ~~~ Call the Domainwarning HTA
- bchkDomainWarning = Window.ShowModalDialog("Domainwarning.hta", "Domainwarning", "dialogWidth:30;dialogHeight:15;Center:Yes;help:No;Resizable:No;Scroll:NO;")
-
- ' ~~~ If tick box checked, set reg to not show again
- If bchkDomainWarning Then
- Call RegWrite(TOOLKITKEY & "ShowDomainWarning","0", "REG_SZ")
- End If
- End If
- Else
- ShowDomainWarning = False
- End If
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: CloseDomainWarning()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Called upon click of the domain warning ok button.
- ' *** Checks if "do not show again" was checked
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub CloseDomainWarning()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ' ~~~ If tick box checked, set reg to not show again
- If document.all("chkDomainWarning").checked Then
- ' ~~~ If checkbox is tick, set the returnvalue to True
- window.returnvalue = True
- End If
- Self.Close()
-
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetRootFolder
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns the application root folder (location of .HTA files)
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function GetRootFolder
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Dim sCmd, iStart, iEnd
-
- ' ~~~ Define command line, start and end
- sCmd = oImagine.CommandLine
- iStart = 1
- iEnd = InStrRev(sCmd, "\")
-
- ' ~~~ If first character is a quote, skip it
- If Left(sCmd, 1) = Chr(34) Then iStart = 2
-
- ' ~~~ Return path
- GetRootFolder = Mid(sCmd, iStart, iEnd - iStart)
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetAppname
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns the application filename with the .hta removed
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function GetAppname
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Dim sCmd, iSlash, iDot
- sCmd = oImagine.CommandLine
- iSlash = InStrRev(sCmd, "\")+1
- iDot = InStrRev(sCmd, ".")
-
- GetAppname = Mid(sCmd, iSlash, iDot-iSlash)
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetRadio()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns the value of a checked radio button
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function GetRadio(sRadioGroup)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Dim oRadio
-
- For Each oRadio in document.getElementsByName(sRadioGroup)
- If oRadio.Checked Then GetRadio=oRadio.Value
- Next
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: ShowHelp()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Display the online help file
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub ShowHelp()
- Dim sHelpFile, sHelpTopic
-
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ' set default help file
- sHelpFile = "sectools.chm"
-
- ' determine which help file to run
- Select Case GetAppname()
- Case "Accessibility"
- sHelpFile = "accessibility.chm"
- sHelpTopic = "3-1-1-AccessibilityOptions.htm"
- Case "DiskProtect"
- sHelpTopic = "3-4-0-WDP.htm"
- Case "GetStarted"
- sHelpTopic = "3-2-0-GettingStarted.htm"
- Case "ProfileMgr"
- sHelpTopic = "3-3-0-ProfileManager.htm"
- Case "Restrict"
- sHelpTopic = "3-5-0-UserRestrictions.htm"
- Case Else
- sHelpTopic = ""
- End Select
-
- ' open the help file
- Call oShell.Run("hh.exe """ & GetRootFolder & "\" & sHelpFile & "::/" & sHelpTopic & """", 1, True)
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Rollover(sId, sImg)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Hover buttons
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub Rollover(sId,sImg)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- document.all(sId).src = "graphics/" & sImg
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Submit()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Process submit button
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub Submit()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- If Validate() Then
- Call Action()
- Self.Close
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: onkeydown()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This subroutine is executed on the click Help F1
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub onkeydown()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- ' ~~~ Handle all the common keys
- select case (window.event.keycode)
- case 112 ' ~~~ F1 is clicked
- Call ShowHelp()
- case 116 ' ~~~ F5 is clicked
- window.event.returnvalue = False
- End select
-
- ' ~~~ Handle Tool specific keys
- HTAKeyDown()
- End sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Highlight(objBtn,bOn)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This sub is executed to highlight the common buttons
- ' *** in all HTA
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub Highlight(objBtn, bOn)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- If bOn Then
- objBtn.filters.Light.Enabled = true
- objBtn.filters.Light.Clear
- objBtn.filters.Light.AddAmbient 255,255,255,90
- objBtn.filters.Light.AddAmbient 255,255,255,25
-
- Else
- objBtn.filters.Light.Clear
- objBtn.filters.Light.Enabled = false
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: BodyDisable(bDisable)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This sub is executed to disable the body during load and
- ' *** change the cursor to wait icon in all HTA.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub BodyDisable(bDisable)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Dim oControls, oControl
-
- ' ~~~ Derickc - We must not set bProcessing here. There are cases we want the UI
- ' ~~~ to be enabled yet processing is underway. (Getting Started, for example.)
- ' ~~~ bProcessing should be set with each action.
-
- ' ~~~ Derickc - I removed this line: bProcessing = bDisable
-
- If bDisable = True Then
- oBody.Style.cursor = "wait"
- Else
- oBody.Style.cursor = "auto"
- End If
- set oControls = oBody.all
- For each oControl in oControls
- oControl.disabled = bDisable
- Next
-
- ' ~~~ This allows UI to immediately update by yielding to IE... oShell created by design - DO NOT REMOVE
- dim oShell
- set oShell = createobject("wscript.shell")
- call oShell.run(chr(34) & oShell.ExpandEnvironmentStrings("%SCTPath%") &"bin\AccessibilityTool.exe" & chr(34),0, True)
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Unload()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This sub is executed while closing the hta
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub Unload()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- UnLoadObjects()
- HTAUnLoad()
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: OnBeforeUnload()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This sub is executed before closing the hta
- ' *** Checks whether any processing is going on while closing
- ' *** the HTA
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function OnBeforeUnload()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ' ~~~ Exit this function if HTA is not processing while closing
- If Not bProcessing Then Exit Function
-
- ' ~~~ Prompt the user whether to leave the HTA open or close the HTA
- If Window.confirm(L_sBeforeUnloadWarning_TEXT) = False Then
- ' ~~~ If processing should continue, then indicate Unload is cancelled and send the next dialog two ESC keys
- window.event.returnvalue = False
- oShell.SendKeys("{esc}{esc}")
- Else
- ' ~~~ If processing should not continue, close, wait for five seconds and then Terminate this HTA
- Window.SetTimeout "TerminateHTA", 5000, "VBScript"
- Exit Function
- End If
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: TerminateHTA()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This sub is to terminate the mshta process that is
- ' *** still running after closing the HTA
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub TerminateHTA()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim colProcesses, oProcess, sCommandline
- ' ~~~ Look for the running HTA process with the same command-line as this one and terminate it
- Set colProcesses = oWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = 'mshta.exe'")
-
- If colProcesses.Count > 0 Then
- For Each oProcess in colProcesses
- sCommandline = Right(oProcess.commandLine, Len(oImagine.commandLine))
- If sCommandline = oImagine.commandline Then
- oProcess.Terminate
- Exit For
- End If
- Next
- End If
- End Sub