如何更新此.HTA以在Win7中使用

时间:2014-05-13 18:38:20

标签: c++ csv windows-7-x64 hta

我有一个用于收集服务器磁盘空间的HTA,它将该信息导出到CSV文件中。由于我们升级到Win7,因此它不会导出,因为它使用WinXP" SAFRCFileDlg.FileSave"。我正在寻找一种方法来使用这个HTA与Win7,但我需要知道我可以做些什么来绕过这个XP脚本。我无法从xp添加dll。

我想发布整个脚本,以便您可以看到其中涉及的所有内容。问题出在" Sub Export"。任何帮助将不胜感激。这个脚本很好用且易于使用,它可以很好地显示所有信息,但我无法将其导出数据。

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         

'''''''''''&#39 ;''''''''''''& #39;'''''''''''&#39 ;''''''''''''& #39;'''''''     子出口

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

'''''''''''&#39 ;''''''''''''& #39;'''''''''''&#39 ;''''''''''''& #39;'''''''''''     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

'''''''''''&#39 ;''''''''''''& #39;'''''''''''&#39 ;''''''''''''& #39;''''''''

1 个答案:

答案 0 :(得分:0)

如果HTA在身体某处添加它。

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

然后使用此代码打开对话框。

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