如何使用其标签访问USB驱动器并使用CMD导航
问题描述:
例如,我想知道是否可以使用其标签访问USB驱动器我可以使用PowerShell导航到驱动器,但我想知道如何在CMD中执行与此类似的操作
I would like to know if it's possible to access a usb drive using its label, for example I can navigate to the drive with PowerShell but I would like to know how to do something similar to this in CMD
$usbPath = Get-WMIObject Win32_Volume | ? { $_.Label -eq 'volumelabel' } | select name ; cd $usbPath.name
答
如果您仍然想使用 wmi 的问题,那么您已经足够了特权,然后使用
If you still wanted to use wmi and you have sufficient privileges to use
加载 wmic 的问题,方法是使用 VOL
命令
For %G In (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)Do @Vol %G: 2>NUL|%__AppDir__%find.exe /I "volumelabel">NUL&&CD /D %G:
@For %%G In (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
) Do @Vol %%G: 2>NUL | %__AppDir__%find.exe /I "volumelabel" >NUL && CD /D %%G:
您不仅可以检查每个可能的驱动器号,还可以使用 MountVol
将其减少为仅挂载的驱动器号:
Instead of just checking every possible drive letter, you could reduce that to only mounted drive letters by using MountVol
:
来自 cmd 的问题:
For /F "Delims=\ " %G In ('"%__AppDir__%mountvol.exe 2>NUL|%__AppDir__%find.exe ":\""') Do @Vol %%G 2>NUL|%__AppDir__%find.exe /I "volumelabel">NUL&&CD /D %%G
@For /F "Delims=\ " %%G In ('"%__AppDir__%mountvol.exe 2>NUL|%__AppDir__%find.exe ":\""'
) Do @Vol %%G 2>NUL | %__AppDir__%find.exe /I "volumelabel" >NUL && CD /D %%G
如果您仍然想使用 wmi 的问题,那么您已经足够了特权,然后使用
Path Win32_Volume
,(或其别名 Volume
)……
If you still wanted to use wmi and you have sufficient privileges to use
Path Win32_Volume
, (or its alias Volume
), with it then…
来自 cmd 的问题:
For /F "Skip=1Tokens=2" %G In ('%__AppDir__%wbem\WMIC.exe Volume Where "Label='volumelabel'" Get DriveLetter^,Name 2^>NUL')Do @CD /D %G
然后从 batch-file :
@For /F "Skip=1 Tokens=2" %G In (
'%__AppDir__%wbem\WMIC.exe Volume Where "Label='volumelabel'" Get DriveLetter^,Name 2^>NUL'
) Do @CD /D %G
否则,您可以改用 Path Win32_LogicalDisk
,(或其别名 LogicalDisk
)…
Otherwise you could use Path Win32_LogicalDisk
, (or its alias LogicalDisk
) instead…
来自 cmd 的问题:
For /F "Skip=1Tokens=2" %G In ('%__AppDir__%wbem\WMIC.exe LogicalDisk Where "VolumeName='volumelabel'" Get DeviceID^,Name 2^>NUL')Do @CD /D %G
然后从 batch-file :
@For /F "Skip=1 Tokens=2" %%G In (
'%__AppDir__%wbem\WMIC.exe LogicalDisk Where "VolumeName='volumelabel'" Get DeviceID^,Name 2^>NUL'
) Do @CD /D %%G