angadsingh007 Posted February 24, 2005 Share Posted February 24, 2005 @echo off:DETERMINEecho Determing Installation CD-ROM driveFOR %%i IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\CD.txt SET CDROM=%%i:IF EXIST %CDROM% GOTO CDROMFOUNDnircmd infobox "Please insert the installation CD-ROM into the drive to continue" "Installation CD-ROM Not Found!"GOTO DETERMINE:CDROMFOUNDecho CD-ROM Drive is %CDROM%This script determines the CD-ROM drive and puts the value into the environment variable - %CDROM%.Usage: Just use the "CALL <script>" command to use and u'll get the %CDROM% variable set. Make sure u have a "cd.txt" file in ur cd's root. (or put any other file and rename here )Use the above script if u are performing a CD-based post-installation from WPI or Batch scripts .... Cool Feature : Displays a message to the user if the required CD-ROM is not loaded into the drive ... again and again... until it is inserted Requirements: nircmd ( get it here - NirCMD HomepagehereI just got some free time and wanted to start posting on msfn so i posted this Flames // suggestions // comments welcome Link to comment Share on other sites More sharing options...
Alanoll Posted February 24, 2005 Share Posted February 24, 2005 Does the variable stay set even after the batch script is exited?I'm sure it doesn't after the parent exits, but does this keep it alive even in the parent?and again....this was onsite as well. Just not a prompt telling the user the disc wasn't inserted. Link to comment Share on other sites More sharing options...
RyanVM Posted February 24, 2005 Share Posted February 24, 2005 you could also have it look for an already existing file like Win51IP (or IC if you use home) rather than adding extra files to the CD Link to comment Share on other sites More sharing options...
angadsingh007 Posted February 25, 2005 Author Share Posted February 25, 2005 @AlanollEVERYTHING is onsite. We can just improve things. And yes, its just the pop-up to insert the CD.it keeps alive in the parent script if u use the "CALL" command.it dies after script executionwhat the heck? --- call it again @RyanVMya sure... look for any file u want... or look for the i386 folder even.if u want perfect matching of the cd... make the batch script test for the md5 hash of any file... Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 25, 2005 Share Posted February 25, 2005 (edited) Here A Vbs Script That determines The Cd varible on error resume next Dim strDriveLetter, intDriveLetter, ts, fs, fso, RB1, RB2 Set Shell = WScript.CreateObject("WScript.Shell") set WshShell = CreateObject("WScript.Shell") V= vbCrLf Function ActionCDCopyConst CDROM = 4On Error Resume NextSet fs = CreateObject("Scripting.FileSystemObject")strDriveLetter = ""For intDriveLetter = Asc("A") To Asc("Z")Err.ClearIf fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM ThenIf Err.Number = 0 ThenstrDriveLetter = Chr(intDriveLetter)Exit ForEnd IfEnd IfNext Set fso = CreateObject("Scripting.FileSystemObject") CD=strDriveLetter If (fso.FileExists(CD & ":\i386\winnt32.exe")) Then Msg4=space(7) & "Check File Was There" RB1 = (WshShell.Popup (CD & ":\i386\winnt32.exe" & V & "Was There", 7,Msg4, 0 + 48 + 4096)) 'CopyXP Else Msg4=space(7) & "File Missing" RB2 = (WshShell.Popup (CD & ":\i386\winnt32.exe" & V & "Was Not There", 7,Msg4, 0 + 48 + 4096)) Msgbox "Place XP CD In The Cd Rom" & V & "Than Press Key To Continue",0+64,"Waiting For Cd" End If end function ActionCDCopy This Script Will copy XP To %systemdrive%\XPCD Edited January 4, 2006 by gunsmokingman Link to comment Share on other sites More sharing options...
angadsingh007 Posted February 25, 2005 Author Share Posted February 25, 2005 @gunsmokingmanThanks man Link to comment Share on other sites More sharing options...
GreenMachine Posted February 25, 2005 Share Posted February 25, 2005 I love when this comes back around ...Here is my code for getting the install drive from the registry:FOR /F "TOKENS=3" %%I IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "SourcePath" ^| FINDSTR "SourcePath"') DO SET INSTALLCD=%%~dI(That should all be on one line. My tribute to Johnny, King of the One Liners) Link to comment Share on other sites More sharing options...
angadsingh007 Posted February 25, 2005 Author Share Posted February 25, 2005 Thanks GreenMachineHere is Version 2 of the codeNEW FEATURES:-first uses the reg method and then the file method -includes a settings section -includes the option of failing after trying a definite number of times-allows you to set which file to find@echo offREM =================SETTINGS==================REM ================(Important)==================REM This is the file to search on the CD-ROM DriveREM Eg. - \WIN51, \I386\txtsetup.sif. \CD.txtSET CDFILE=\cd.txtREM This is the maximum number of time to retry before failingREM Note: Set this to -1 if you want to retry infinite timesSET /A MAX_RETRIES=5REM ==============END OF SETTINGS===============:DETERMINEecho Determing Installation CD-ROM driveREM ============Determing by reg method=============FOR /F "TOKENS=3" %%I IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "SourcePath" | FINDSTR "SourcePath"') DO SET CDROM=%%~dIIF EXIST %CDROM% GOTO CDROMFOUNDREM =========Determing by searching for files/folders=======FOR %%i IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:%CDFILE% SET CDROM=%%i:IF EXIST %CDROM% GOTO CDROMFOUNDREM ==========Other Methods======================REM (include ur own methods with the above IF statement after each one)REM =======Script will reach here if all above fails==========SET /a NUM_OF_RETRIES=%NUM_OF_RETRIES%+1nircmd infobox "Please insert the installation CD-ROM into the drive to continue (Retry No.:%NUM_OF_RETRIES%)" "Installation CD-ROM Not Found!"REM Tell the script not to try after a fixed number of retriesIF %MAX_RETRIES%==-1 GOTO SKIPRETRYCHECKIF %NUM_OF_RETRIES%==%MAX_RETRIES% GOTO NOTFOUND:SKIPRETRYCHECKGOTO DETERMINEREM ============CD-ROM DRIVE FOUND==============:CDROMFOUNDecho CD-ROM Drive is %CDROM%GOTO ENDREM ==========CD-ROM DRIVE NOT FOUND==============:NOTFOUNDnircmd infobox "The CD-ROM Drive was not found. (Retry No.:%NUM_OF_RETRIES%)" "The Installation cannot continue"EXIT:END 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