VBS - 尝试显示卷名

时间:2018-01-25 20:03:29

标签: batch-file vbscript hta

我正在尝试这样,因此卷名称将显示在驱动器号旁边。此代码是基于名称和可用空间的驱动器选择的一部分。

我很确定我必须在vbs行中添加一些东西,但我不知道该怎么做。该代码最初由aGerman制作,可以找到here

Call :hdd-info
ECHO -------TESTING EXIT------
ECHO      ANY KEY TO EXIT
PAUSE >nul
EXIT


::MUST ALL BE LAST THING IN BATCH FILE
:hdd-info    
@echo off &setlocal
set "GB=1073741824"
for /f "skip=1 delims=" %%i in ('wmic logicaldisk get DeviceID^,FreeSpace^,Size^,volumename') do (
  for /f "tokens=1-3" %%j in ("%%i") do call :output %%j %%k %%l %%m 
)
goto :eof
:output
if "%3"=="" (
  rem echo Unable to discover the drive properties.
  goto :eof
)
for /f "tokens=1-5" %%i in (
  'mshta vbscript:Execute("CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(FormatNumber(%3/%GB%, 2) & "" "" & FormatNumber((%3-%2)/%GB%, 2) & "" "" & FormatNumber(%2/%GB%, 2) & "" "" & Round((%3-%2)*50/%3)):Close"^)'
) do (
  set "size=      %%i"
  set "used=      %%j"
  set "free=      %%k"
  set /a "nUsed=%%l, nFree=50-%%l"
  set "namz=      %%m"
)
echo(
echo       %namz% %1 %free:~-10% GB Available

希望它显示:

[卷名] [驱动器号] [GB中的可用空间]

2 个答案:

答案 0 :(得分:0)

新鲜的眼睛为我解决了这个问题。必须将Write-Host 'Warning Will Robinson!'更改为tokens=1-5

tokens=1-4

答案 1 :(得分:0)

On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_LogicalDisk")

For Each objItem in colItems
    Wscript.echo objItem.Caption & " " & objItem.VolumeName & " " & FormatNumber(objItem.FreeSpace/2^30, 0) & " GB free of " & " " & FormatNumber(objItem.Size/2^30, 0) & " GB"
Next

如果启动上述脚本cscript //nologo file.vbs,它将打印到控制台窗口。