Jump to content

Drive assignment


zigzagph

Recommended Posts

I have created a bootable PE image and can boot it using a UFD. Everything works as expected except that I would like to access the .wim file located on UFD drive after the ram disk has been loaded. Does anyone know how to re-access the UFD drive or restart the USB port so the drive is assigned a drive letter? I have tried to use devcon and other scripting techniques but none have been successful at re-assigning the UFD a drive letter other then physically removing the drive and re-inserting it back into the port.

Link to comment
Share on other sites


I haven't tried, but I would think a rescan command from the diskpart prompt should do the trick. Either way, diskpart.exe is the tool you should be using. Its built into PE and supports scripting so check it out.

Link to comment
Share on other sites

  • 2 weeks later...

What version of winpe are you using?

I could send you a vb script that assigns a drive letter via diskpart based on the label of the UFD so that you can script a automactic load of your wim works for me in winpe 2005 and winpe 2.

In fact I dig it out from work tomorrow and post it here

Link to comment
Share on other sites

here is the vb script to set a driver letter to a disk/UFD based on the label of that device...

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim WshShell, wshFSO

Set WshShell = CreateObject("WScript.Shell")
Set wshFSO = CreateObject("Scripting.FileSystemObject")

' change these to customize the script...
const msVolumeName = "kingston" ' i.e. Dan
const msNewDriveLetter = "Q" ' i.e. Q

' don't change these constants!
const msDiskPartbatch = "runDP.bat" ' i.e. runDP.bat
const msDiskPartLVScript = "dp_listv.txt"
const msDPVolumesTemp = "diskvolumes.txt"

' create scripts - nice and clean this way
call createDPScript(msDiskPartBatch)
call createDP_LVscript(msDiskPartLVScript)

' get the volumes
call GetDiskVolumes(msDiskPartbatch, msDPVolumesTemp)

' get the volume ID from the output
miDiskID = getVolumeLetterAndIDfromFile(msDPVolumesTemp, msVolumeName)

' change the letter....
call GhangeDiskVolumes("changescript.txt", miDiskID, msNewDriveLetter)

' clean up output files.....
call deleteifexists(msDiskPartbatch)
call deleteifexists(msDiskPartLVScript)
call deleteifexists("diskvolumes.txt")
call deleteifexists("changelog.txt")
call deleteifexists("changescript.txt")

' done.
call msgbox("Done!")

wscript.quit


private sub DeleteIfExists(rsFileName)
on error resume next
if wshfso.fileexists(rsFileName) = true then
wshfso.deletefile(rsFilename)
end if
end sub

private sub createDP_LVScript(rsFileName)
dim DPLVScriptFile

' write the file
Set DPLVScriptFile = wshfso.OpenTextFile(rsFileName, ForWriting, true)
DPLVScriptFile.writeline "list volume"
DPLVScriptFile.close
end sub

private sub createDPScript(rsFileName)
dim DPScriptFile

' write the file
Set DPScriptFile = wshfso.OpenTextFile(rsFileName, ForWriting, true)
DPScriptFile.writeline "@echo off"
DPScriptFile.writeline "diskpart /s %1 > %2"
DPScriptFile.close
end sub


private function getVolumeLetterAndIDfromFile(rsFileName, rsVolumeName)
dim diskPartVolumes
dim miDiskID, maLine
dim mbFound

Set diskPartVolumes = wshfso.OpenTextFile(rsFileName, ForReading, false)

mbFound = false

while diskPartVolumes.atendofstream = false
maLine = split(diskPartVolumes.readline," ")

'msOut = ""
'for mi=1 to ubound(maline)
' msOut = msOut & mi & " - " & maline(mi) & vbcrlf
'next

if ubound(maLine) > 11 then
if ucase(maline(11)) = ucase(rsVolumeName) then
'msgbox "Volume " & rsVolumeName & " is on letter " & maline(8) & " thats

volume no " & maline(3)
miDiskID = maline(3)
mbFound = true
end if
end if

'msgbox msOut

wend

if mbFound = true then
getVolumeLetterAndIDfromFile = miDiskID
else
call msgbox("Unable to find volume " & rsVolumeName & " in " & rsFilename)
end if

diskPartVolumes.close
end function


private sub GetDiskVolumes(rsBatchfile, rsFileName)
dim oExec
Set oExec = WshShell.Exec(rsBatchfile & " " & msDiskPartLVScript & " " & rsFileName)

Do While oExec.Status = 0
WScript.Sleep 500
Loop
end sub


private sub GhangeDiskVolumes(rsFileName, riVolumeID, rsNewLetter)
dim diskPartVolumes

' write the file
Set diskPartVolumes = wshfso.OpenTextFile(rsFileName, ForWriting, true)
diskPartVolumes.writeline "select volume " & riVolumeID
diskpartvolumes.writeline "assign letter=" & left(rsNewLetter,1)
diskpartvolumes.close

' execute
dim oExec
Set oExec = WshShell.Exec(msDiskPartbatch & " " & rsFileName & " changelog.txt")

Do While oExec.Status = 0
WScript.Sleep 500
Loop
end sub

just change it to the letter and label you require.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...