无忧启动论坛

标题: 批处理 获取 U盘 可移动硬盘盘符 [打印本页]

作者: h4rra    时间: 2013-10-26 18:56
标题: 批处理 获取 U盘 可移动硬盘盘符

【方法一】fsutil

@echo off
for %%a in (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 (
  for /f %%h in ('fsutil fsinfo drivetype %%a:^|findstr "Removable.* 可移动"') do (
    set DriveU=%%h
  )
)
echo.%DriveU%
pause

【方法二】WMIC
@echo off
for /f "tokens=2 delims==" %%a in ('wmic LogicalDisk where "DriveType='2'" get DeviceID /value') do (
  set DriveU=%%a
)
echo.%DriveU%
pause

【方法三】BAT + VBS (优点是可以兼容Win2000系统)

@echo off
<%~fs0 more +10>%temp%\GetU.vbs
for /f %%a in ('cscript /nologo "%temp%\GetU.vbs"') do (
  set "DriveU=%%a"
)
echo.%DriveU%
pause
goto :eof

''''''''''''''''''''''''''''''''''''''''''''''''''''
Set Fso = CreateObject("Scripting.FileSystemObject")
Set B = Fso.Drives

For Each A in B
    If A.DriveType = 1 Then
       aDisk = aDisk & A.DriveLetter & ": "
    End If
Next
aDisk = Replace(aDisk, "A: ","")
WScript.Echo aDisk

----------------------------------------------------------------by h4rra----------------------------------------------------------------------
不要等到失去才知道曾经拥有
机会来临,但已经错过

作者: redmason    时间: 2013-10-30 09:36
方法二 好点




欢迎光临 无忧启动论坛 (http://wuyou.net/) Powered by Discuz! X3.3