Why use fsutil.exe
which generally requires elevated privileges, when you can do it using the built in dir
command?
@For /F "Tokens=1,* EOL=[ Delims=)" %%G In ( Dir %SystemDrive% /W /-C ) Do @For /F %%I In ("%%H") Do @Set "FreeSpace=%%I"
@Echo %FreeSpace%
您也可以使用<条码>W.exe条码>执行任务,无需升级:
@For /F "Tokens=1,* Delims==" %%G In ( %SystemRoot%System32wbemWMIC.exe Volume Where "DriveLetter= %SystemDrive% " Get FreeSpace /Value 2^>NUL ) Do @For /F %%I In ("%%H") Do @Set "FreeSpace=%%I"
@Echo(%FreeSpace%
You could even get the assistance of powershell.exe
, once again without elevation:
@For /F %%G In ( %SystemRoot%System32WindowsPowerShellv1.0powershell.exe -NoProfile -Command "(Get-Volume -DriveLetter %SystemDrive:~,1% ).SizeRemaining" 2^>NUL ) Do @Set FreeSpace=%%G"
@Echo(%FreeSpace%
如果你仍然希望使用你提议的<代码>fsutil.exe的指挥效用做同样的事,那么以下几句可能就足够了:
@Set "FreeSpace=" & For /F "Tokens=1,* Delims=:" %%G In ( %SystemRoot%System32fsutil.exe Volume DiskFree %SystemDrive% 2^>NUL ) Do @For /F %%I In ("%%H") Do @If Not Defined FreeSpace Set "FreeSpace=%%I"
@Echo(%FreeSpace:,=%