简体   繁体   中英

How can I update this .HTA to be used in Win7

I have an HTA that we use to gather our servers disk space, and it exports that information into a CSV file. Since we upgraded to Win7, it will not export because it uses WinXP "SAFRCFileDlg.FileSave". I am looking for a way to use this HTA with Win7, but I need to know what I can do to get around this XP script. I cannot add the dll from xp.

I wanted to post the entire script so that you can see all that is involved in it. The issue is in the "Sub Export". Any help will be appreciated. This script is nice and easy to use, it displays all of the information nicely, but I can't get it to export the data.

Sub DiskSpace

'On Error Resume Next

strComputer = WriteDiskSpace.Value

Document.getElementById("WriteDiskSpace1").innerhtml = ""

Set objOption = Document.createElement("OPTION")
    objOption.Text = "---------------------------------------"
    objOption.Value = "--------------------------------------"
    WriteDiskSpace1.Add(objOption)
Set objOptionA = Document.createElement("OPTION")
    objOptionA.Text = strComputer
    objOptionA.Value = strComputer
    WriteDiskSpace1.Add(objOptionA)
Set objOptionB = Document.createElement("OPTION")
    objOptionB.Text = "---------------------------------------"
    objOptionB.Value = "--------------------------------------"
    WriteDiskSpace1.Add(objOptionB)

Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Volume")
For Each objItem in colItems

If objItem.Capacity > "" then

'Total Space in TeraBytes
strDiskGB = Int(objItem.Capacity /1073741824)
strDiskTB = ABS(strDiskGB /1028)
strDiskSubTotal = Int(strDiskTB * 1000)
strDiskTotal = ABS(strDiskSubTotal / 1000)

'Total Used Space in TeraBytes
strUsedGB = Int((objItem.Capacity - objItem.FreeSpace)/ 1073741824)
strUsedTB = ABS(strUsedGB /1028)
strUsedSubTotal = Int(strUsedTB * 1000)
strUsedTotal = ABS(strUsedSubTotal / 1000)

'Total Free Space
 strFreeGB = Int(objItem.FreeSpace /1073741824)
strFreeTB = ABS(strFreeGB /1028)
strFreeSubTotal = Int(strFreeTB * 1000)
strFreeTotal = ABS(strFreeSubTotal / 1000)

strTitle1 = "Volume : "
strTitle2 = "Total Space : "
strTitle3 = "Used Space : "
strTitle4 = "Free Space : "
strTitle5 = "Free Percentage : "

strText1 = strTitle1 & objItem.Name
strText2 = strTitle2 & strDiskTotal & " TB"
strText3 = strTitle3 & strUsedTotal & " TB"
strtext4 = strTitle4 & strFreeTotal & " TB"
strText5 = strTitle5 & Round((objItem.FreeSpace /objItem.Capacity)*100,2) & " %"

Set objOption1 = Document.createElement("OPTION")
objOption1.Text = strText1
objOption1.Value = strText1
WriteDiskSpace1.Add(objOption1)

Set objOption7 = Document.createElement("OPTION")
objOption7.Text = ""
objOption7.Value = ""
WriteDiskSpace1.Add(objOption7)

Set objOption2 = Document.createElement("OPTION")
objOption2.Text = strText2
objOption2.Value = strText2
WriteDiskSpace1.Add(objOption2)

Set objOption3 = Document.createElement("OPTION")
objOption3.Text = strText3
objOption3.Value = strText3
WriteDiskSpace1.Add(objOption3)

Set objOption4 = Document.createElement("OPTION")
objOption4.Text = strText4
objOption4.Value = strText4
WriteDiskSpace1.Add(objOption4)

Set objOption5 = Document.createElement("OPTION")
objOption5.Text = strText5
objOption5.Value = strText5
WriteDiskSpace1.Add(objOption5)

Set objOption6 = Document.createElement("OPTION")
objOption6.Text = ""
objOption6.Value = ""
WriteDiskSpace1.Add(objOption6)

Else    
End If

Next

End Sub         

''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub Export

strArray = Array("Server", "Server", "Server", "Server", "Server")

Set objDialog = CreateObject("SAFRCFileDlg.FileSave")
objDialog.FileName = "Storage_Data.CSV"
objDialog.FileType = "CSV File"
intResult = objDialog.OpenFileSaveDlg

If intResult Then
Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(objDialog.FileName)
objFile.Close

Else
Exit Sub
End If

Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(objDialog.FileName)
objFile.Close

For Each ComArr in strArray

strComputer = ComArr

Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(objDialog.FileName, 8, True)
        objFile.WriteLine "SERVER NAME,Volume,Total Space,,Used Space,,Free Space,,Free         Percentage"
objFile.WriteLine strComputer
objFile.Close

On Error Resume Next

Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Volume")
For Each objItem in colItems

If objItem.Capacity > "" then

'Total Space in TeraBytes
strDiskGB = Int(objItem.Capacity /1073741824)
strDiskTB = ABS(strDiskGB /1028)
strDiskSubTotal = Int(strDiskTB * 1000)
strDiskTotal = ABS(strDiskSubTotal / 1000)

'Total Used Space in TeraBytes
strUsedGB = Int((objItem.Capacity - objItem.FreeSpace)/ 1073741824)
strUsedTB = ABS(strUsedGB /1028)
strUsedSubTotal = Int(strUsedTB * 1000)
strUsedTotal = ABS(strUsedSubTotal / 1000)

'Total Free Space
strFreeGB = Int(objItem.FreeSpace /1073741824)
strFreeTB = ABS(strFreeGB /1028)
strFreeSubTotal = Int(strFreeTB * 1000)
strFreeTotal = ABS(strFreeSubTotal / 1000)

strText1 = objItem.Name
strText2 = strDiskTotal & ", TB"
strText3 = strUsedTotal & ", TB"
strtext4 = strFreeTotal & ", TB"
strText5 = Round((objItem.FreeSpace /objItem.Capacity)*100,2) & " %"

Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(objDialog.FileName, 8, True)
objFile.WriteLine "," & strText1 & "," & strText2 & "," & strText3 & "," & strText4 & "," & strText5
objFile.Close

Else
End If
Next
Next
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub TotalSpace

Document.getElementById("WriteDiskSpace1").innerhtml = ""

strArray = Array("Server", "Server", "Server", "Server", "Server", "Server")

For Each ComArr in strArray

strComputer = ComArr

Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Volume")
For Each objItem in colItems

If objItem.Capacity > "" then

'Total Space in TeraBytes
strDiskGB = Int(objItem.Capacity /1073741824)
strDiskTB = ABS(strDiskGB /1028)
strDiskSubTotal = Int(strDiskTB * 1000)
strDiskTotal = ABS(strDiskSubTotal / 1000)

'Total Used Space in TeraBytes
strUsedGB = Int((objItem.Capacity - objItem.FreeSpace)/ 1073741824)
strUsedTB = ABS(strUsedGB /1028)
strUsedSubTotal = Int(strUsedTB * 1000)
strUsedTotal = ABS(strUsedSubTotal / 1000)

'Total Free Space
strFreeGB = Int(objItem.FreeSpace /1073741824)
strFreeTB = ABS(strFreeGB /1028)
strFreeSubTotal = Int(strFreeTB * 1000)
strFreeTotal = ABS(strFreeSubTotal / 1000)

strTotalStorage = ABS(strTotalStorage + strDiskTotal)
strTotalUsed = ABS(strTotalUsed + strUsedTotal)
strTotalFree = ABS(strTotalFree + strFreeTotal)

Else
End If

If objItem.Name = "C:\" then

strTotalStorage = ABS(strTotalStorage - strDiskTotal)
strTotalUsed = ABS(strTotalUsed - strUsedTotal)
strTotalFree = ABS(strTotalFree - strFreeTotal)

Else

End If
Next
Next

Set objOption = Document.createElement("OPTION")
objOption.Text = "Total : " & strTotalStorage & " TB"
objOption.Value = "Total : " & strTotalStorage & " TB"
WriteDiskSpace1.Add(objOption)

Set objOption1 = Document.createElement("OPTION")
objOption1.Text = "Used : " & strTotalUsed & " TB"
objOption1.Value = "Used : " & strTotalUsed & " TB"
WriteDiskSpace1.Add(objOption1)

Set objOption2 = Document.createElement("OPTION")
objOption2.Text = "Free : " & strTotalFree & " TB"
objOption2.Value = "Free : " & strTotalFree & " TB"
WriteDiskSpace1.Add(objOption2)

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

If it's an HTA add this somewhere in the body.

<OBJECT id=Dlg classid="CLSID:3050F4E1-98B5-11CF-BB82-00AA00BDCE0B" width=0 height=0>

Then use this code to open the dialog.

strUPath = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop"
strStartPath = strUPath & "\Select a file"
strFilter = "Text (*.txt;*.csv)| *.txt;*.csv|VBScript (*.vbs;*.vbc)|*.vbs;*.vbc|HTML (*.htm;*.html;*.hta)|*.htm;*.html;*.hta|All Files (*.*)|*.*|"
strCaption = "Select a File to Replace"
strSelectedFile = Dlg.openfiledlg(CStr(strStartPath), , CStr(strFilter), CStr(strCaption))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM