Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title>Publication Updater</title>
- <hta:application id="oPU"
- applicationname="Publication Updater"
- border="thick"
- caption="yes"
- contextmenu="no"
- icon=""
- maximizebutton="no"
- minimizebutton="no"
- navigable="no"
- scroll="no"
- showintaskbar="yes"
- singleinstance="yes"
- sysmenu="yes"
- version="1.0.1"
- windowstate="normal"
- >
- <style type="text/css">
- body{
- text-align: center;
- }
- .vAlign{
- vertical-align: top;
- }
- #driveSelect{
- text-align: left;
- }
- </style>
- <script language="VBScript">
- Const SOURCE_PATH = "Your folder path"
- Dim aImageCollection : aImageCollection = Array("images\loading.gif", "images\go.jpg", "images\warning.jpg", "images\error.jpg")
- Dim aMessageStatus : aMessageStatus = Array("Please wait while we check for updates...", "Version up-to-date", "Version needs to be updated", "Operation failed; Contact Administrator")
- '''<summary>Executes when the HTA is opened</summary>
- Sub Window_OnLoad
- Call SetupWindow(500, 250, True)
- Call SetInitalView()
- Call CheckVersion(0)
- End Sub
- '''<summary>Allows the window to be resized and centered</summary>
- '''<param name="iWidth">New width of the window</param>
- '''<param name="iHeight">New height of the window</param>
- '''<param name="bCenter">Determines if the window should be centered</param>
- '''<remarks>You can specify a width and height of 0,0 to use defaults</remarks>
- Sub SetupWindow(iWidth, iHeight, bCenter)
- If iWidth <> 0 And iHeight <> 0 Then
- Me.ResizeTo iWidth, iHeight
- End If
- If bCenter Then
- With Document.Body
- Me.MoveTo ((Screen.Width - .OffsetWidth) / 2), ((Screen.Height - .OffsetHeight) / 2)
- End With
- End If
- End Sub
- '''<summary>Sets up the inital view of the HTA</summary>
- '''<remarks>This is used to keep the Window_OnLoad methods from being cluttered</remarks>
- Sub SetInitalView()
- Call ToggleElementVisibility(driveSelect)
- Call ToggleElementVisibility(copy)
- Call UpdateDriveSelection(2)
- Call UpdateImageAndCaption(aImageCollection(0), aMessageStatus(0))
- End Sub
- '''<summary>Gets all the drives for a specific drive type</summary>
- '''<param name="iDriveType">An integer defining the type of drive to retreive</param>
- '''<returns>A array with the drive letter and volume name in x & x+1 format</returns
- '''<remarks>If element 0 is "C:\" then element 1 is the name for the volume</remarks>
- Function GetLocalDrives(iDriveType)
- Dim aDrives()
- Dim iCurrentIndex : iCurrentIndex = 0
- Dim oDriveCollection : Set oDriveCollection = _
- GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") _
- .ExecQuery("SELECT Name, VolumeName FROM Win32_LogicalDisk WHERE DriveType='" & iDriveType & "'")
- ReDim aDrives(oDriveCollection.Count * 2)
- For Each drive In oDriveCollection
- aDrives(iCurrentIndex) = drive.Name & "\"
- aDrives(iCurrentIndex + 1) = drive.VolumeName
- iCurrentIndex = iCurrentIndex + 2
- Next
- GetLocalDrives = aDrives
- End Function
- '''<summary>Copys a folder to the specified destination</summary>
- '''<param name="sDestination">The path where the folder should be copied to</summary>
- Sub CopyFolder(sDestination)
- On Error Resume Next
- Err.Clear()
- Call CreateObject("Scripting.FileSystemObject").CopyFolder(SOURCE_PATH, sDestination, True)
- If Err.Number <> 0 Then
- Call UpdateImageAndCaption(aImageCollection(3), aMessageStatus(3))
- Else
- Call UpdateImageAndCaption(aImageCollection(1), aMessageStatus(1))
- End If
- 'Err.Clear()
- End Sub
- '''<summary>Updates the HTA's selectable drives</summary>
- '''<remarks>This method is hard-coded with the HTML select element's id</remarks>
- Sub UpdateDriveSelection(iDriveType)
- Dim aDrives : aDrives = GetLocalDrives(iDriveType)
- For i=0 To UBound(aDrives) - 1 Step 2
- Set driveOption = Document.CreateElement("option")
- driveOption.Value = aDrives(i)
- driveOption.Text = "(" & aDrives(i) & ") " & aDrives(i+1)
- drives.Options.Add(driveOption)
- Next
- End Sub
- '''<summary>Updates the HTA's status image & the caption for the image</summary>
- '''<remarks>This method is hard-coded with the HTML image & span element's id</remarks>
- Sub UpdateImageAndCaption(sImagePath, sCaptionText)
- If sImagePath <> "" Then
- displayImage.src = sImagePath
- End If
- imageCaption.InnerText = sCaptionText
- End Sub
- '''<summary>Updates the HTA's version date</summary>
- '''<remarks>This method is hard-coded with the HTML span element's id</remarks>
- Sub UpdateVersionDate(sDate)
- versionDate.InnerText = "Version: " & sDate
- End Sub
- '''<summary>Toggles the "Display" property of an HTML element reference passed to it</summary>
- '''<param name="oHtmlElement">The HTML element you want to hide</param>
- '''<remarks>This method will automatically suppress any errors that occur while attempting to hide the element</remarks>
- Sub ToggleElementVisibility(oHtmlElement)
- On Error Resume Next
- If LCase(oHtmlElement.Style.Display) = "none" Then
- oHtmlElement.Style.Display = "block"
- Else
- oHtmlElement.Style.Display = "none"
- End If
- Err.Clear()
- End Sub
- 'Up to user to implement
- 'This is only showing an example
- Sub CheckVersion(iTest)
- 'If the version is correct do the following:
- '-Keep "Update" options hidden
- '-change image and its' caption
- '-Update the version date and status
- 'If the version is incorrect do the following:
- '-Expand the window to show the "Update" options
- '-change the image and its' caption
- '-Update the version date and status
- Select Case iTest
- Case 1
- 'Version up-to-date
- Call SetupWindow(500, 275, True)
- Call UpdateImageAndCaption(aImageCollection(1), aMessageStatus(1))
- Call UpdateVersionDate(Now)
- Case 2
- 'Version not up-to-date
- Call SetupWindow(500, 350, True)
- Call UpdateImageAndCaption(aImageCollection(2), aMessageStatus(2))
- Call ToggleElementVisibility(driveSelect)
- Call ToggleElementVisibility(copy)
- Call UpdateVersionDate(Now)
- Case 3
- 'Error
- Call UpdateImageAndCaption(aImageCollection(3), aMessageStatus(3))
- Call UpdateVersionDate(Now)
- Case Else
- 'Don't change anything, just display the load screen
- End Select
- End Sub
- </script>
- </head>
- <body>
- <div id="wrapper" class="contentWrapper">
- <div id="imageContainer">
- <img id="displayImage" />
- <br />
- <span id="imageCaption"></span>
- </div>
- <br />
- <div id="information">
- <span id="versionDate"></span>
- </div>
- <hr />
- <br />
- <div id="driveSelect">
- <span class="vAlign">Select the drive you would like to copy the files to:</span>
- <select id="drives"></select>
- </div>
- <br />
- <button id="copy" onClick="CopyFolder(drives.options(drives.SelectedIndex).Value)">Update</button>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment