VBS - 尝试显示卷名
VBS - Trying to display volume name
我正在努力使卷名显示在驱动器号旁边。此代码是基于名称和自由 space.
的驱动器选择的一部分
我很确定我必须在 vbs 行中添加一些东西,但我不确定该怎么做。代码原是一个德国人做的,可以找到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
想要显示:
[卷名][盘符][免费 space GB]
新鲜的眼睛为我解决了这个问题。必须将 tokens=1-5
更改为 tokens=1-4
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-4" %%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-4" %%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
GOTO :eof
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
它将打印到控制台 window。
我正在努力使卷名显示在驱动器号旁边。此代码是基于名称和自由 space.
的驱动器选择的一部分我很确定我必须在 vbs 行中添加一些东西,但我不确定该怎么做。代码原是一个德国人做的,可以找到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
想要显示:
[卷名][盘符][免费 space GB]
新鲜的眼睛为我解决了这个问题。必须将 tokens=1-5
更改为 tokens=1-4
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-4" %%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-4" %%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
GOTO :eof
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
它将打印到控制台 window。