1

我发现了这个输出逻辑磁盘大小的简单脚本。

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")

For Each objDisk in colDisks
    Wscript.Echo "DeviceID: " & objDisk.DeviceID & " with a Disk Size: " & objDisk.Size

Next

我的 VBS 技能很差,需要帮助:

  1. 我想获得一个大小数量的只有 C 和 D 分区加在一起
  2. 如果大小(来自第 1 步)不等于 500 GB(介于 450,000,000,000 和 550,000,000,000 之间),我需要计算机提示警告并“按任意键”继续
  3. 我不想要一个弹出窗口,因为这将在 WinPE 的提示下运行,是否可以在提示窗口中获取输出?

我问了很多所以提前谢谢你如果你能帮忙

4

1 回答 1

1

您将需要使用 cscript 启动您的脚本。此代码来自http://ask.metafilter.com/79481/vbscript-printing-to-command-line 这允许回显转到命令行而不是消息框。

CheckStartMode
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")

For Each objDisk in colDisks
    If(objDisk.DeviceID="C:" or objDisk.DeviceID="D:") then
        Wscript.Echo "DeviceID: " & objDisk.DeviceID & " with a Disk Size: " & objDisk.Size
        TotalSize = CCur(TotalSize) + CCur(objDisk.Size)
    End if
Next
If(TotalSize <450000000000 or TotalSize >550000000000) then
    Wscript.Echo "Disk size of " & TotalSize & " is out of range."
    Wscript.Echo "Press enter to contine."
    z = WScript.StdIn.Read(1)
End if

Wscript.Echo "Complete, Press enter to end."
z = WScript.StdIn.Read(1)
Sub CheckStartMode
     ' Returns the running executable as upper case from the last \ symbol
     strStartExe    = UCase( Mid( wscript.fullname, instrRev(wscript.fullname, "\") + 1 ) )

     If Not strStartExe = "CSCRIPT.EXE" Then
          ' This wasn't launched with cscript.exe, so relaunch using cscript.exe explicitly!
          ' wscript.scriptfullname is the full path to the actual script

          set           oSh = CreateObject("wscript.shell")
          oSh.Run   "cscript.exe """ & wscript.scriptfullname & """"
          wscript.quit

     End If
End Sub
于 2012-08-09T21:44:38.343 回答