如何从脚本中检测已启动 USB 驱动器的驱动器盘符?

发布于 2024-07-16 00:23:31 字数 527 浏览 4 评论 0原文

我从可启动 UFD 启动 WinPE 2,并且需要检测驱动器号以便告诉 ImageX 在哪里可以找到 WIM。 但是,根据我要成像的机器,安装的驱动器也不同。

我需要一种方法来一致地将 UFD 安装在 P: 或其他位置。 有没有办法检测启动计算机的驱动器号,或者有其他方法将 WIM 文件的位置传递给可从 startnet.cmd 访问的变量?

TechNet 上的其他人也遇到了同样的问题。

http: //social.technet.microsoft.com/Forums/en-US/itprovistadeployment/thread/3e8bb8db-a1c6-40be-b4b0-58093f4833be?prof=required#

I'm launching WinPE 2 from a bootable UFD, and I need to detect the drive letter in order to tell ImageX where to find the WIM. However, depending on the machine I'm imaging, there are different mounted drives.

I need a way to consistently mount the UFD at, say, P: or something. Is there a way to detect the letter of the drive from which the machine was booted, or another way to pass the location of my WIM file to a variable accessible from startnet.cmd?

Here's someone else with the same issue over at TechNet.

http://social.technet.microsoft.com/Forums/en-US/itprovistadeployment/thread/3e8bb8db-a1c6-40be-b4b0-58093f4833be?prof=required#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

污味仙女 2024-07-23 00:23:31

此 VBScript 将为每个可移动驱动器显示一条消息(字母:描述),可以轻松修改以搜索特定驱动器并返回字母。

 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where MediaType = 11")

For Each objDisk in colDisks
    Wscript.Echo objDisk.DeviceID & objDisk.Description
Next

不知道这是否有帮助。

This VBScript will show a message for each removable drive (letter:description), could be easily modified to search for a particular drive and return the letter.

 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where MediaType = 11")

For Each objDisk in colDisks
    Wscript.Echo objDisk.DeviceID & objDisk.Description
Next

Don't know if that helps at all.

善良天后 2024-07-23 00:23:31

与此处提到的其他解决方案相比,这是一个不太通用的解决方案,但似乎有一种特定的方法可以确定“RAM 驱动器启动”Windows PE 操作系统从哪个底层卷启动。 来自 Windows 自动安装工具包

如果您没有启动 Windows
部署服务,最佳方式
确定 Windows PE 从何处启动
是首先检查
PEBootRamdiskSourceDrive 注册表项。
如果不存在,请扫描驱动器
正确的 PEBootType 并查找
某种标识的标记文件
启动驱动器。

(相关注册表值位于 HKLM\SYSTEM\CurrentControlSet\Control 下。)

It's a less generic solution than the others mentioned here, but there appears to be a specific way to determine which underlying volume a "RAM-drive-booted" Windows PE OS was booted from. From the documentation on Windows PE in the Windows Automated Installation Kit:

If you are not booting Windows
Deployment Services, the best way to
determine where Windows PE booted from
is to first check for
PEBootRamdiskSourceDrive registry key.
If it is not present, scan the drives
of the correct PEBootType and look for
some kind of tag file that identifies
the boot drive.

(The registry value in question sits under HKLM\SYSTEM\CurrentControlSet\Control.)

oО清风挽发oО 2024-07-23 00:23:31

这是一个非最佳解决方案。 在这种情况下,UFD 必须有一个特定的名称,该名称将传递给脚本,该脚本将搜索每个可能的驱动器号以查找匹配项。 依赖具有相同名称的闪存驱动器可能不切实际。

还是希望有人能给出更好的答案!

setlocal

:: Initial variables
set TMPFILE=%~dp0getdrive.tmp
set driveletters=abcdefghijklmnopqrstuvwxyz
set MatchLabel_res=

for /L %%g in (2,1,25) do call :MatchLabel %%g %*

if not "%MatchLabel_res%"=="" echo %MatchLabel_res%

goto :END

:: Function to match a label with a drive letter. 
::
:: The first parameter is an integer from 1..26 that needs to be 
:: converted in a letter. It is easier looping on a number
:: than looping on letters.
::
:: The second parameter is the volume name passed-on to the script
:MatchLabel

:: result already found, just do nothing 
:: (necessary because there is no break for for loops)
if not "%MatchLabel_res%"=="" goto :eof

:: get the proper drive letter
call set dl=%%driveletters:~%1,1%%

:: strip-off the " in the volume name to be able to add them again further
set volname=%2
set volname=%volname:"=%

:: get the volume information on that disk
vol %dl%: > "%TMPFILE%" 2>&1

:: Drive/Volume does not exist, just quit
if not "%ERRORLEVEL%"=="0" goto :eof

set found=0
for /F "usebackq tokens=3 delims=:" %%g in (`find /C /I "%volname%" "%TMPFILE%"`) do set found=%%g

:: trick to stip any whitespaces
set /A found=%found% + 0


if not "%found%"=="0" set MatchLabel_res=%dl%:
goto :eof

:END

if exist "%TMPFILE%" del "%TMPFILE%"
endlocal

Here's a non-optimal solution. In this case, the UFD has to have a specific name, which is passed to the script which searches every possible drive letter for a match. It's probably not practical to rely on the flash drives all having the same name.

Still hoping someone pops by with a better answer!

setlocal

:: Initial variables
set TMPFILE=%~dp0getdrive.tmp
set driveletters=abcdefghijklmnopqrstuvwxyz
set MatchLabel_res=

for /L %%g in (2,1,25) do call :MatchLabel %%g %*

if not "%MatchLabel_res%"=="" echo %MatchLabel_res%

goto :END

:: Function to match a label with a drive letter. 
::
:: The first parameter is an integer from 1..26 that needs to be 
:: converted in a letter. It is easier looping on a number
:: than looping on letters.
::
:: The second parameter is the volume name passed-on to the script
:MatchLabel

:: result already found, just do nothing 
:: (necessary because there is no break for for loops)
if not "%MatchLabel_res%"=="" goto :eof

:: get the proper drive letter
call set dl=%%driveletters:~%1,1%%

:: strip-off the " in the volume name to be able to add them again further
set volname=%2
set volname=%volname:"=%

:: get the volume information on that disk
vol %dl%: > "%TMPFILE%" 2>&1

:: Drive/Volume does not exist, just quit
if not "%ERRORLEVEL%"=="0" goto :eof

set found=0
for /F "usebackq tokens=3 delims=:" %%g in (`find /C /I "%volname%" "%TMPFILE%"`) do set found=%%g

:: trick to stip any whitespaces
set /A found=%found% + 0


if not "%found%"=="0" set MatchLabel_res=%dl%:
goto :eof

:END

if exist "%TMPFILE%" del "%TMPFILE%"
endlocal
七色彩虹 2024-07-23 00:23:31

为了更详细地阐述鲁本的答案,这是我的批处理文件:

wpeutil UpdateBootInfo
for /f "usebackq skip=1 tokens=3 delims= " %%l in ( `reg query HKLM\System\CurrentControlSet\Control /v PEBootRAMDiskSourceDrive` ) do set "PendrivePath=%%l"
set "PendriveLetter=%PendrivePath:~0,1%"
echo The boot pendrive's drive letter is %PendriveLetter%

To elaborate reuben's answer in more detail, here is my batch file:

wpeutil UpdateBootInfo
for /f "usebackq skip=1 tokens=3 delims= " %%l in ( `reg query HKLM\System\CurrentControlSet\Control /v PEBootRAMDiskSourceDrive` ) do set "PendrivePath=%%l"
set "PendriveLetter=%PendrivePath:~0,1%"
echo The boot pendrive's drive letter is %PendriveLetter%
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文