Fixed drive letter in WinPE

This script can be added to a WinPE environment to ensure that the removable boot media always have a specific drive letter.

All you need to do is create a file called “72821acd-379a-478a-a2c6-1ebd72cbead5.txt” on the media that you want to have a fixed drive letter, in this example drive letter M is assigned. After this add the script as a startup script into your PE boot media.

Option Explicit

Dim objWMIService
Dim objFileSystemObject
Dim colVolumes
Dim objVolume

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")

Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")
For Each objVolume in colVolumes
    If objFileSystemObject.FileExists(objVolume.DriveLetter & "\72821acd-379a-478a-a2c6-1ebd72cbead5.txt") Then
        objVolume.DriveLetter = "M:"
    End If


Leave a Reply