How can I detect the drive letter of a booted USB drive from script?

10,901

Solution 1

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.

Solution 2

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.)

Share:
10,901
Doug Chase
Author by

Doug Chase

Positive and pragmatic product leader with ten years of experience in B2B and B2C software. Skilled in analyzing the marketplace, synthesizing product vision, and then communicating that vision internally and externally through roadmaps, requirements, and product marketing activities. Seasoned manager of cohesive teams. Strong competencies in research and validation, idea management, prioritization and roadmapping, consensus-building, SDLC process development, product analytics, technical writing, Scrum/Kanban product ownership, and user experience/interface design. I'm passionate about the democratization of content creation and about working with skilled creators and craftspeople of all kinds, including those in media, engineering, software and the arts.

Updated on June 21, 2022

Comments

  • Doug Chase
    Doug Chase about 2 years

    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#