2

我正在尝试自动化我们的成像过程。我们有多个具有不同图像的计算机型号,它们都存储在一个带有 WinPE 的 USB 驱动器上。我已经创建了一个脚本,它给了我选项Choice来选择我想要成像的计算机,但问题是取决于我正在成像的计算机,USB 驱动器的字母会发生变化。我正在寻找一个批处理文件,它将找到 USB 驱动器并将驱动器号更改为“X:”,以便Choice脚本可以使用静态驱动器号正常运行以查找图像文件。

我搜索并找到了一个脚本,该脚本将通过名称“Ace”找到 USB 驱动器并输出驱动器号,但无法弄清楚如何获取该驱动器并将其更改为“X:”

for /f "tokens=3 delims= " %%A in ('echo list volume ^| diskpart ^| findstr "Ace"') do (set Acedrive=%%A)

我到目前为止是这样的:

echo off
cls
Echo Image Selection Menu
Echo =======================
Echo 1 Dell D820
Echo 2 Dell E6510
Echo 3 Dell E6520
Echo 4 Lenovo T431S
Echo 5 Lenovo T440S
Echo 6 Lenovo M73 Tiny
Echo =======================
Choice /C 123456 /M "What computer are you trying to image?"
If Errorlevel 6 goto 6
If Errorlevel 5 goto 5
If Errorlevel 4 goto 4
If Errorlevel 3 goto 3
If Errorlevel 2 goto 2
If Errorlevel 1 goto 1

Goto End

:6
cls
imagex /apply M73.wim 1 g:
Goto End

:5
cls
imagex /apply T440S.wim 1 g:
Goto End

:4
cls
imagex /apply T431S.wim 1 g:
Goto End

:3
cls
imagex /apply E6520.wim 1 g:
Goto End

:2
cls
imagex /apply E6510.wim 1 g:
Goto End

:1
cls
imagex /apply D820.wim 1 g:
:End

所以这基本上只是让我选择我正在成像的计算机,然后为该 wim 运行相关的 imagex 命令。任何帮助将不胜感激!

谢谢

4

3 回答 3

3

试试这段代码:

for /f "tokens=2,3 delims= " %%A in ('echo list volume ^| diskpart ^| findstr "Ace"') do (
set Acedrive=%%B
(echo select volume %%A
echo assign letter=X) | diskpart
)

希望对您有所帮助。

于 2015-04-20T18:51:36.077 回答
0

您正在寻找该命令的鲜为人知且使用频率较低的/d选项,该选项cd将移动驱动器和目录。

@echo off
for /f "tokens=3 delims= " %%A in ('echo list volume ^| diskpart ^| findstr "Ace"') do (set Acedrive=%%A)
cd /d %Acedrive%:\

请记住以管理员身份运行脚本,否则 diskpart 将在新窗口中打开并且代码将不起作用。

于 2015-04-16T21:41:45.947 回答
0

您可以尝试像这批一样查找连接的 USB 密钥的驱动器号:

@echo off
Mode con cols=98 lines=10 & Color 9E
Title Searching the Drive letter of your USB Key by Hackoo 2014
echo.
ECHO   *******************************************************************************************
echo.
echo                           Searching the drive letter of your USB Key .......
echo.
ECHO   *******************************************************************************************
wmic logicaldisk get DeviceID,DriveType /Format:CSV > %Tmp%\tmp.txt 
for /f "skip=2 tokens=1-3 delims=," %%a in ('%COMSPEC% /a /c type "%Tmp%\tmp.txt"') do echo %%b %%c >> %Tmp%\tmp2.txt
for /f "tokens=1" %%i in ('%COMSPEC% /a /c type "%Tmp%\tmp2.txt" ^|Find "2"') Do (set MyUSBDrive=%%i)
Del %Tmp%\tmp.txt & Del %Tmp%\tmp2.txt
cls
echo.
ECHO   *******************************************************************************************
echo.
echo                          The drive letter of your USB Key is  %MyUSBDrive%
echo.
ECHO   *******************************************************************************************
pause
于 2015-04-20T18:09:10.293 回答