Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Mr.John_Doe

Getting the CD-Drive-Letter in PE2

Recommended Posts

Hello,

I write a script for autodeploying images from a dvd. But I need to get the driveletter from the dvd-drive in PE.

Is there a way like a systemvariable to get this letter or a way to detect via vbscript. I have tried this but without success:


function suche_profilordner(nutze_konf)
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
for i = a to z
wscript.echo " Suche DVD-Laufwerk bei Buchstaben " & i & "."
If objFso.FolderExists(i & ":\imagex\" & nutze_konf) = true Then
letter = i
end if
next
if i <> "" then
suche_profilordner = i
else
suche_profilordner = "Fehler:Buchstabe nicht gefunden"
end if

end function

Share this post


Link to post
Share on other sites

I just use a batch file and diskpart to change the drive letter during my startup process because it was using a letter I wanted my hard drive partitions to use, but you can use the Win32_CDROMDrive.Drive instance as well.

Batch to change the CD drive letter

echo list volume > X:\ListCD.txt
FOR /F "tokens=2,4" %%i IN ('diskpart /s X:\ListCD.txt') DO @IF /I %%j == CD_ROM SET CDROMVOL=%%i
IF DEFINED CDROMVOL echo select volume %CDROMVOL% > X:\ChangeCD.txt
IF DEFINED CDROMVOL echo assign letter=K: >> X:\ChangeCD.txt
IF DEFINED CDROMVOL diskpart /s X:\ChangeCD.txt

VBScript to find CD drive letters

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colCD = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")

For Each objCD In colCD ' If there are multiple CD drives, this loop will only set the variable for the last one listed
strCDLetter = objCD.Drive
Next

Share this post


Link to post
Share on other sites

This won't fit perfectly for you as-is, but this is part of the script I use for CD stuff. I set the cdrom drive with the cdname "WINPE" to G:

If the drive is ready and is a cdrom drive, has a volumename and that name is "WINPE" then

{if the drive is not G: but G: exists, then move G: via diskpart to another letter}

create a text file selecting the drive via drive letter and assign it to be G:, via diskpart.


Set oFileSystem = New Scripting.FileSystemObject

For Each vDrive In oFileSystem.Drives
If vDrive.IsReady Then
If vDrive.DriveType = 4 Then
If LenB(vDrive.VolumeName) <> 0 And vDrive.VolumeName = "WINPE" Then
If vDrive.DriveLetter <> "G" Then
If FolderExists("G:\") Then
ShellAndWait "DISKPART /S X:\WINDOWS\SYSTEM32\NU2MENU\REMOVEG.TXT", vbHide
End If
If (Not FolderExists("G:\")) And LenB(vDrive.DriveLetter) <> 0 Then
Dim oFileWrite As TextStream

Set oFileWrite = oFileSystem.CreateTextFile("X:\WINDOWS\TEMP\FIXCD.TXT", True)

oFileWrite.WriteLine "SELECT VOLUME " & vDrive.DriveLetter
oFileWrite.WriteLine "ASSIGN LETTER=G"
oFileWrite.Close

Set oFileWrite = Nothing

ShellAndWait "DISKPART /S X:\WINDOWS\TEMP\FIXCD.TXT", vbHide
End If
End If
End If
End If

End If
Next

Share this post


Link to post
Share on other sites

I guess I'll throw in my two cents. I have also written a script to detect the cd-rom drive letter. The main difference from the other two is that I had to account for external drives that are attached via USB to some of our systems. The problem I found is that when WinPE loads, most of the time those drives are not detected right away. There is usually a lag in the mounting time of the drive. So my script addresses that problem by using a timer (timer.vbs) and a loop to look for the drive again. Works perfectly on all my systems.

Dim taskCmd, i, objShell, objFso, collSettings, objItem, cdrom, lword
Set objShell = CreateObject("WScript.Shell")
Set objFso = CreateObject("Scripting.FileSystemObject")

'determine cd-rom drive letter
For i = 1 To 7
taskCmd = "%comspec% /c diskpart /s X:\Windows\system32\probeDrives.txt"
objShell.Run taskCmd,0,true
Set collSettings = objFso.Drives
For Each objItem in collSettings
If objItem.DriveType = 4 Then
lword = objItem.DriveLetter
If objFso.FileExists(lword & ":\sources\boot.wim") Then
cdrom = lword & ":"
Exit For
End If
End If
Next
If cdrom <> "" Or i = 7 Then Exit For
taskCmd = "%comspec% /c cscript X:\Windows\system32\timer.vbs"
objShell.Run taskCmd,0,true
Next

'check whether cdrom was set
If cdrom = "" Then
taskCmd = "Could not determine CD-ROM drive letter"
MsgBox taskCmd,16,"Error"
End If

probeDrives:

list volume
exit

timer.vbs

Dim exittime, x
x = 0
exittime = timer + 8
do while timer < exittime
x = x + 1
loop

Edited by zorphnog

Share this post


Link to post
Share on other sites

How does one know what letter(s) the CD (and other) drives were assigned?

I have to accomodate not only multiple HDD partitions on a system, but multiple network shares, too.

Share this post


Link to post
Share on other sites
I just use a batch file and diskpart to change the drive letter during my startup process because it was using a letter I wanted my hard drive partitions to use, but you can use the Win32_CDROMDrive.Drive instance as well.

Batch to change the CD drive letter

echo list volume > X:\ListCD.txt
FOR /F "tokens=2,4" %%i IN ('diskpart /s X:\ListCD.txt') DO @IF /I %%j == CD_ROM SET CDROMVOL=%%i
IF DEFINED CDROMVOL echo select volume %CDROMVOL% > X:\ChangeCD.txt
IF DEFINED CDROMVOL echo assign letter=K: >> X:\ChangeCD.txt
IF DEFINED CDROMVOL diskpart /s X:\ChangeCD.txt

VBScript to find CD drive letters

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colCD = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")

For Each objCD In colCD ' If there are multiple CD drives, this loop will only set the variable for the last one listed
strCDLetter = objCD.Drive
Next

Wondering just how I'd call this or where to implement it - that "echo list volume" has to run under DISKPART, doesn't it?

Share this post


Link to post
Share on other sites

What exactly are you trying to do? If you just want to view them, type 'list volume' within the diskpart shell.

Share this post


Link to post
Share on other sites

I have a need to change the CD-ROM letter to accommodate an image we are deploying that uses letters C, D, and E.

We also have network shares to pull images from, and those are assigned J, K, L, and M.

There are 3 other shares for tools and log reports - I, T, and W.

So I need something to relocate the CD-ROM drive on a system (and there could be 2 of them) - to other drive letters.

I tried your setup and while it ran, it couldn't determine any CD-ROM drive letter.

Then I tried WreX's setup, but was unsure where and how exactly the pieces would be executed.

Share this post


Link to post
Share on other sites

I use my batch code in a .bat file called by \Windows\System32\startnet.cmd so it runs at start up and before any of my other routines are launched.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...