如何在不弹出 window 的情况下创建 VB 脚本文件

how to create a VB script file without a pop up window

我用谷歌搜索了一个可以正常工作的代码, 但是当我在任务管理器中安排它时出现问题..在每个弹出屏幕之后我需要单击确定..然后只有文件得到 updated.Please 让我知道要做什么更改以便在 运行 VBS 它静静地更新文件。

实际代码: 来源:http://www.wisesoft.co.uk/scripts/vbscript_disk_space_usage_report.aspx

OPTION EXPLICIT

CONST strComputer = "."
CONST strReport = "D:\diskspace.txt"

DIM objWMIService, objItem, colItems
DIM strDriveType, strDiskSize, txt

SET objWMIService = GETOBJECT("winmgmts:\" & strComputer & "\root\cimv2")
SET colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
txt = "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
FOR EACH objItem in colItems

    DIM pctFreeSpace,strFreeSpace,strusedSpace

    pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
    strDiskSize = Int(objItem.Size /1073741824) & "Gb"
    strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb"
    strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) & "Gb"
    txt = txt & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf

NEXT

writeTextFile txt, strReport
wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt

' Procedure to write output to a text file
PRIVATE SUB writeTextFile(BYVAL txt,BYVAL strTextFilePath)
  DIM objFSO,objTextFile
  SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
  SET objTextFile = objFSO.CreateTextFile(strTextFilePath)
  objTextFile.Write(txt)
  objTextFile.Close
  SET objTextFile = NOTHING
END SUB

如果您删除该行,wscript.echo 生成的弹出消息,代码将 运行 静默

wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt

使用 cscript script_file.vbs 而不是 wscript script_file.vbs 调用脚本。