WMIC return 当 运行 直接 .cmd 文件时没有可用的实例
WMIC return No Instance(s) Available when run directly .cmd file
我正在尝试在 for 循环中查询 WMIC。当我运行查询命令在cmd.exe
WMIC PATH Win32_DiskPartition WHERE (DeviceID="Disk #0, Partition #1") GET Type /value
效果不错。但是我 运行 query.cmd,它显示没有可用的实例。
https://abload.de/img/ooo6vkr6.png
@ECHO OFF
SET "InputFile=C:\Users\NIMDA\AppData\Local\Temp\aa.txt"
IF EXIST "%InputFile%" (DEL /f /q "%InputFile%")
SETLOCAL EnableExtensions EnableDelayedExpansion
FOR /F "delims=" %%G IN ('"WMIC PATH Win32_DiskPartition WHERE (DeviceID="Disk #0, Partition #1") GET Type /value"') DO (
FOR /F "tokens=*" %%H IN ("%%G") DO (
CALL ECHO %%H>> "%InputFile%"
)
)
ENDLOCAL
pause
如何解决这个问题?
这里有几个例子,它们以不同的方式完成!
使用Find
:
@Echo Off
Set "InputFile=%TEMP%\aa.txt"
For /F Tokens^=4* %%A In ('
"WMIC Partition Where "DeviceID Like 'Disk #0%%'" Get DeviceID,Type 2>NUL|Find "Partition #1""
')Do @For /F Tokens^=* %%A In ("%%B")Do >>"%InputFile%" Echo Type=%%A
使用Like
:
@Echo Off
Set "InputFile=%TEMP%\aa.txt"
For /F Tokens^=* %%A In ('
"WMIC Partition Where "DeviceID Like 'Disk #0%%' And DeviceID Like '%%Partition #1'" Get Type /Value 2>NUL"
')Do @For /F Tokens^=* %%B In ("%%A")Do >>"%InputFile%" Echo %%B
我正在尝试在 for 循环中查询 WMIC。当我运行查询命令在cmd.exe
WMIC PATH Win32_DiskPartition WHERE (DeviceID="Disk #0, Partition #1") GET Type /value
效果不错。但是我 运行 query.cmd,它显示没有可用的实例。
https://abload.de/img/ooo6vkr6.png
@ECHO OFF
SET "InputFile=C:\Users\NIMDA\AppData\Local\Temp\aa.txt"
IF EXIST "%InputFile%" (DEL /f /q "%InputFile%")
SETLOCAL EnableExtensions EnableDelayedExpansion
FOR /F "delims=" %%G IN ('"WMIC PATH Win32_DiskPartition WHERE (DeviceID="Disk #0, Partition #1") GET Type /value"') DO (
FOR /F "tokens=*" %%H IN ("%%G") DO (
CALL ECHO %%H>> "%InputFile%"
)
)
ENDLOCAL
pause
如何解决这个问题?
这里有几个例子,它们以不同的方式完成!
使用Find
:
@Echo Off
Set "InputFile=%TEMP%\aa.txt"
For /F Tokens^=4* %%A In ('
"WMIC Partition Where "DeviceID Like 'Disk #0%%'" Get DeviceID,Type 2>NUL|Find "Partition #1""
')Do @For /F Tokens^=* %%A In ("%%B")Do >>"%InputFile%" Echo Type=%%A
使用Like
:
@Echo Off
Set "InputFile=%TEMP%\aa.txt"
For /F Tokens^=* %%A In ('
"WMIC Partition Where "DeviceID Like 'Disk #0%%' And DeviceID Like '%%Partition #1'" Get Type /Value 2>NUL"
')Do @For /F Tokens^=* %%B In ("%%A")Do >>"%InputFile%" Echo %%B