我需要确定硬盘驱动器设备的制造商ID的驱动器号(或者反之亦然,我也可以这样做)。
检索制造商ID的命令:
WMIC.exe DiskDrive Get /Format:List
输出示例(分割并格式化HTML实体):
PNPDeviceID=DISK&VEN_WDC_WD10&PROD_02FAEX-00Z3A0
检索驱动器号的命令:
WMIC.exe Volume Get /Format:List
示例输出:
DriveLetter=C:
问题是我无法从两个输出中关联任何有用的属性来进行查询,我的意思是我不知道该如何使用制造商ID来搜索每个ID的驱动器号,我可以看不到识别ID的驱动器号的任何方法。
所以,当我获得DeviceID
DISK&VEN_WDC_WD10&PROD_02FAEX-00Z3A0
时,我需要将其转换为等效的driveLetter,即C:
,仅此而已。我尝试使用
WMIC
工具,因为我不知道如何使用Windows提供的 native 命令行工具来关联此信息,但是对于WMI
类,我完全不需要我完成此任务,我可以接受使用也应接受Windows中其他预先安装的工具(也许是BCDedit
吗?)或VBScript
语言的解决方案,但是对于环境情况,我无法使用任何其他语言(包括本地PowerShell
)来完成此任务,并且也不能使用第三方工具(例如Microsoft提供的Devcon
实用程序。我需要这样做的原因是要完成此脚本,该脚本应检索并排除DriveLetter
C:
的DeviceID:@Echo OFF & REM Mode con cols=150 lines=50
:: Exclude this drive during the process.
Set "ExcludedDrive=C:"
:: This variable should be set later,
:: Stores the device ID of the drive letter excluded above.
Set "ExcludedID="
REM ************
REM PSEUDO CODE:
REM ************
REM
REM To get Volume Information:
REM WMIC.exe Volume Get /Format:List
REM WMIC.exe Volume Where 'DriveLetter="C:"' Get /Format:CSV
REM
REM To get DiskDrive Information:
REM WMIC.exe DiskDrive Get /Format:List
REM
REM :: Identify the drive letter of each DeviceID to add exclusions
REM For Each %%DriveLetter in %ExcludedDrive% do (
REM
REM :: Retrieve an WMIC Result
REM Set WMIC_Query_Result=¿?
REM Set WMIC_Query_Result_DriveLetter=¿?
REM Set WMIC_Query_Result_DeviceID=¿?
REM
REM If %WMIC_Query_Result_DriveLetter% EQU %%DriveLetter (
REM Set "ExcludedID=%WMIC_Query_Result_DeviceID%"
REM )
REM )
REM
REM ******************
REM END OF PSEUDO CODE
REM ******************
For /F "Tokens=* Delims=" %%a In (
'REG.exe Query "HKLM\SYSTEM\CurrentControlSet\Enum\SCSI" ^| Find /I "Disk&"'
) Do (
Echo "%%a" | Find /I "%ExcludedID%" || (
For /F "Tokens=* Delims=" %%b In ('REG.exe Query "%%~a"') Do (
Reg.exe ADD "%%b\Device Parameters\Disk" /V "UserWriteCacheSetting" /T "REG_DWORD" /D "0x00000000" /F 1>NUL
)
)
)
Pause&Exit
最佳答案
做
diskpart /s diskpart.script
在脚本中有两行
select disk 0
detail disk
帮助?
关于windows - 将硬盘驱动器号转换为相应的设备ID(反之亦然),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22728918/