Mr.John_Doe Posted February 13, 2008 Share Posted February 13, 2008 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 nextif i <> "" then suche_profilordner = ielse suche_profilordner = "Fehler:Buchstabe nicht gefunden"end ifend function Link to comment Share on other sites More sharing options...
WreX Posted February 13, 2008 Share Posted February 13, 2008 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 letterecho list volume > X:\ListCD.txtFOR /F "tokens=2,4" %%i IN ('diskpart /s X:\ListCD.txt') DO @IF /I %%j == CD_ROM SET CDROMVOL=%%iIF DEFINED CDROMVOL echo select volume %CDROMVOL% > X:\ChangeCD.txtIF DEFINED CDROMVOL echo assign letter=K: >> X:\ChangeCD.txtIF DEFINED CDROMVOL diskpart /s X:\ChangeCD.txtVBScript to find CD drive lettersSet 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.DriveNext Link to comment Share on other sites More sharing options...
trtkron Posted February 26, 2008 Share Posted February 26, 2008 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 Link to comment Share on other sites More sharing options...
zorphnog Posted February 27, 2008 Share Posted February 27, 2008 (edited) 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, lwordSet 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 IfprobeDrives:list volumeexittimer.vbsDim exittime, xx = 0 exittime = timer + 8do while timer < exittime x = x + 1loop Edited February 27, 2008 by zorphnog Link to comment Share on other sites More sharing options...
Stratuscaster Posted March 6, 2008 Share Posted March 6, 2008 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. Link to comment Share on other sites More sharing options...
Stratuscaster Posted March 6, 2008 Share Posted March 6, 2008 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 letterecho list volume > X:\ListCD.txtFOR /F "tokens=2,4" %%i IN ('diskpart /s X:\ListCD.txt') DO @IF /I %%j == CD_ROM SET CDROMVOL=%%iIF DEFINED CDROMVOL echo select volume %CDROMVOL% > X:\ChangeCD.txtIF DEFINED CDROMVOL echo assign letter=K: >> X:\ChangeCD.txtIF DEFINED CDROMVOL diskpart /s X:\ChangeCD.txtVBScript to find CD drive lettersSet 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.DriveNextWondering just how I'd call this or where to implement it - that "echo list volume" has to run under DISKPART, doesn't it? Link to comment Share on other sites More sharing options...
zorphnog Posted March 6, 2008 Share Posted March 6, 2008 What exactly are you trying to do? If you just want to view them, type 'list volume' within the diskpart shell. Link to comment Share on other sites More sharing options...
Stratuscaster Posted March 6, 2008 Share Posted March 6, 2008 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. Link to comment Share on other sites More sharing options...
WreX Posted March 11, 2008 Share Posted March 11, 2008 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. Link to comment Share on other sites More sharing options...
Stratuscaster Posted March 12, 2008 Share Posted March 12, 2008 Thanks for the reply - we've got it up and running. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now