Jump to content

N00b Scripting - Determining The Cd Drive


Recommended Posts

@echo off

:DETERMINE
echo Determing Installation CD-ROM drive
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:\CD.txt SET CDROM=%%i:

IF EXIST %CDROM% GOTO CDROMFOUND
nircmd infobox "Please insert the installation CD-ROM into the drive to continue" "Installation CD-ROM Not Found!"
GOTO DETERMINE

:CDROMFOUND
echo 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 :P)

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 :thumbup

Requirements: nircmd ( get it here - NirCMD Homepagehere

I just got some free time and wanted to start posting on msfn so i posted this :D

Flames // suggestions // comments welcome ;)

Link to comment
Share on other sites


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

@Alanoll

EVERYTHING is onsite. We can just improve things. :D

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 execution

what the heck? --- call it again ;)

@RyanVM

ya 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

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 ActionCDCopy
Const CDROM = 4
On Error Resume Next
Set fs = CreateObject("Scripting.FileSystemObject")
strDriveLetter = ""
For intDriveLetter = Asc("A") To Asc("Z")
Err.Clear
If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
If Err.Number = 0 Then
strDriveLetter = Chr(intDriveLetter)
Exit For
End If
End If
Next
    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 by gunsmokingman
Link to comment
Share on other sites

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

Thanks GreenMachine

Here is Version 2 of the code

NEW FEATURES:

-first uses the reg method and then the file method :D

-includes a settings section :P

-includes the option of failing after trying a definite number of times

-allows you to set which file to find

@echo off

REM =================SETTINGS==================
REM ================(Important)==================

REM This is the file to search on the CD-ROM Drive
REM Eg. - \WIN51, \I386\txtsetup.sif. \CD.txt
SET CDFILE=\cd.txt

REM This is the maximum number of time to retry before failing
REM Note: Set this to -1 if you want to retry infinite times
SET /A MAX_RETRIES=5

REM ==============END OF SETTINGS===============

:DETERMINE
echo Determing Installation CD-ROM drive

REM ============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=%%~dI

IF EXIST %CDROM% GOTO CDROMFOUND

REM =========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 CDROMFOUND

REM ==========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%+1

nircmd 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 retries

IF %MAX_RETRIES%==-1 GOTO SKIPRETRYCHECK
IF %NUM_OF_RETRIES%==%MAX_RETRIES% GOTO NOTFOUND
:SKIPRETRYCHECK

GOTO DETERMINE

REM ============CD-ROM DRIVE FOUND==============
:CDROMFOUND
echo CD-ROM Drive is %CDROM%
GOTO END

REM ==========CD-ROM DRIVE NOT FOUND==============

:NOTFOUND

nircmd 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

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...