簡體   English   中英

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

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

我有一個HTA,可用來收集服務器磁盤空間,並將其導出到CSV文件中。 由於我們已升級到Win7,因此它不會導出,因為它使用WinXP“ SAFRCFileDlg.FileSave”。 我正在尋找一種在Win7上使用此HTA的方法,但是我需要知道如何解決XP腳本。 我無法從XP添加dll。

我想發布整個腳本,以便您可以看到其中包含的所有內容。 問題出在“子導出”中。 任何幫助將不勝感激。 該腳本非常好用,易於使用,可以很好地顯示所有信息,但是我無法導出該數據。

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         

'''''''''''''''''''''''''''''''''''''''''''''''' '''''''子導出

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

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

如果是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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM