简体   繁体   English

如何更新要在Win7中使用的.HTA

[英]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. 我有一个HTA,可用来收集服务器磁盘空间,并将其导出到CSV文件中。 Since we upgraded to Win7, it will not export because it uses WinXP "SAFRCFileDlg.FileSave". 由于我们已升级到Win7,因此它不会导出,因为它使用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. 我正在寻找一种在Win7上使用此HTA的方法,但是我需要知道如何解决XP脚本。 I cannot add the dll from xp. 我无法从XP添加dll。

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 '''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''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. 如果是HTA,请将其添加到体内的某个位置。

<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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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