1

我需要从 bat 脚本中获取引导分区的DRIVE NAME 。

我得到的引导分区号reagentc.exe /info如下:

Windows RE location: \\?\GLOBALROOT\device\harddisk0\partition1\Recovery\WindowsRE

但我需要驱动器名称。怎么能从蝙蝠身上找回来?

4

2 回答 2

3

这是我的解决方案。

首先drives.bat使用以下内容创建一个(它将列出逻辑驱动器及其磁盘分区):

@if (@X)==(@Y) @end /* JSCRIPT COMMENT **


@echo off
cscript //E:JScript //nologo "%~f0"
exit /b

// Sources of wisdom:
//http://social.msdn.microsoft.com/Forums/vstudio/en-US/659030c8-bcf5-4542-bbc6-eaf9679e090a/cannot-create-object-wmi-in-javascript
//http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/23/how-can-i-correlate-logical-drives-and-physical-disks.aspx
//http://stackoverflow.com/a/1144788/388389

************** end of JSCRIPT COMMENT **/


String.prototype.replaceAll = function (find, replace) {
    var str = this;
    return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
};


var winmgmts= GetObject("winmgmts:\\\\.\\root\\cimv2")
var drives = winmgmts.ExecQuery( "SELECT * FROM Win32_DiskDrive", null, 48 );
//WScript.Echo(drives);

var drvs = new Enumerator(drives);
for (;!drvs.atEnd();drvs.moveNext()) {
    var drive=drvs.item();

    WScript.Echo( "Physical Disk: " + drive.Caption + " -- " + drive.DeviceID );
    var deviceID = drive.DeviceID.replaceAll( "\\" ,"\\\\");
    var colPartitions = winmgmts.ExecQuery( "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=\"" + 
        deviceID + "\"} WHERE AssocClass =  Win32_DiskDriveToDiskPartition" , null, 48 );

    var colParts = new Enumerator(colPartitions);
    for (;!colParts.atEnd();colParts.moveNext()) {

        var partition=colParts.item();

        //WScript.Echo( "Disk Partition: " + partition.DeviceID );
        var colLogicalDisks = winmgmts.ExecQuery( "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=\"" +
                partition.DeviceID + "\"} WHERE AssocClass = Win32_LogicalDiskToPartition" , null, 48);
        var colLD = new Enumerator(colLogicalDisks);

        if (typeof colLD.item() != "undefined") {
            for (;!colLD.atEnd();colLD.moveNext()) {
                var logicalDisk=colLD.item();
                WScript.Echo( "  Logical Disk: " + logicalDisk.DeviceID + " Disk Partition:  harddisk" + partition.DeviceID.split("#")[1].split(",")[0] + "\\partition" + partition.DeviceID.split("#")[2] );
            }
        } else {
            WScript.Echo( "  Disk Partition: harddisk" + partition.DeviceID.split("#")[1].split(",")[0] + "\\partition" + partition.DeviceID.split("#")[2] );
        }

    }   

}

然后在同一个目录中创建一个re_d.bat(你可以随意调用它)在同一个目录中,内容如下:

@echo off

for /f  "tokens=5,6 delims=\" %%a in ('reagentc.exe /info 2^>nul ^|find /i " Windows RE location:"') do (
    set "re_loc=%%a\%%b"
)



for /f "tokens=2 delims=:" %%a in ('drives.bat ^|find /i "%re_loc%"') do (
    set "re_dsk=%%a"
)

echo RE LOCATION : %re_loc%
echo RE LOGICAL DISK : %re_dsk%:

看看第二个的输出.bat会让你高兴。

于 2014-07-28T12:19:45.143 回答
0

如果驱动器名称是指卷标,那么您可以使用以下内容查找名称中的第 5 个单词将是驱动器名称。

vol %SystemDrive%

在此处输入图像描述

于 2014-07-28T09:21:31.103 回答