Jump to content

FINDCD & SET as VARIABLE in CMD or as batch


ispy

Recommended Posts

Hello All, :thumbup

Go easy here, cus I am new to this forum site & well a bit of a lamer! Incidentally I am working off an XPPRO OS!

I was wondering whether there is a resonably easy way in NT command prompt of being able to identify which drive letter is being used for your CDROM/WRITER (or DVD Drive for that matter) then designating that drive letter as a variable to instruct the batch file looking in that drive to extract say certain files from an XP/2K/2K3/NT OS install CD. Or if someone knows of a small CMD Util that will do this, all the better? Preferably it will need to be able to work off NT/2K/2K3/XP systems. Not asking for much am I, LOL!

I have tried on various forums including this one & have not found one that will work for me as yet!

Regards,

ispy

Link to comment
Share on other sites


copy the code below and save it as a cmd file. when run the console will display various things like drive, path name etc if you use %~d0 in your batch file it should get the CD-Rom drive.

@echo off
echo This script will show several (hopefully) interresting things of the
echo variable %%0
echo.
echo Command executed (%%0) : %0
echo Directories (%%~p0): %~p0
echo Drive (%%~d0): %~d0
echo Filename (no ext.) (%%~n0): %~n0
echo Extension (%%~x0): %~x0
echo Full path + filename (%%~f0): %~f0
echo Modification time (file) (%%~t0): %~t0
echo Filesize (%%~t0): %~t0
pause

Link to comment
Share on other sites

Thanx IcemanND & Benners for your prompt replies,

Firstly, IcemanND I did SEARCH SEARCH but regretably missed the third "SEARCH" on the list LOL! Are there any instructions on how to use your little gizmoes as I have run the .EXE files then opened CMD, typed set to list the variables & no variables listed indicate a CDROM drive as far as I can see. Can you let me know how it works & maybe a couple of practical examples to grasp how it works. I have grabbed DETECTCD2.EXE DETECTCD.EXE & DETECTDRIVE.EXE which one best suits the scenario listed in the 1st posting please?

Secondly, Benners I have made the .CMD file & as you suggest it does indeed report the info that you suggest, then you go on to say that if within a batch file I use %~d0 I will obtain the CDROM Drive letter. Will this be a variable or will it find the actual drive letter "if that is the right term to use". Could you provide a simple working example as a guide please?

Will these two alternatives work within 2K/2K3 & XP?

Regards,

ispy

Link to comment
Share on other sites

If you run DetectCD or DetectDrive you need to run them before you open a cmd window to be able to access them in the cmd window as they write the variables directly to the registry.

for %%a in (C 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 %%a:\WIN51 set CDROM=%%a:

this will set CDROM to the drive that WIN51 was first found on.

to use Brenners method you would need to use the SET command and set a variable to the desired variable in his script.

Link to comment
Share on other sites

Thanx IcemanND & Benners for your prompt replies,

Firstly, IcemanND I did SEARCH SEARCH but regretably missed the third "SEARCH" on the list LOL! Are there any instructions on how to use your little gizmoes as I have run the .EXE files then opened CMD, typed set to list the variables & no variables listed indicate a CDROM drive as far as I can see. Can you let me know how it works & maybe a couple of practical examples to grasp how it works. I have grabbed DETECTCD2.EXE DETECTCD.EXE & DETECTDRIVE.EXE which one best suits the scenario listed in the 1st posting please?

Secondly, Benners I have made the .CMD file & as you suggest it does indeed report the info that you suggest, then you go on to say that if within a batch file I use %~d0 I will obtain the CDROM Drive letter. Will this be a variable or will it find the actual drive letter "if that is the right term to use". Could you provide a simple working example as a guide please?

Will these two alternatives work within 2K/2K3 & XP?

Regards,

ispy

The %~d0 will return the drive letter i.e E: %~d0 is already a variable. you can the add this to the path to the program you want to run. I don't know what it is you are trying to do but for example if you wanted to run an exe that was in the root of the CD you would have

%~d0\filetorun.exe

this would give you E:\filetorun.exe assuming the CD drive was E:

Link to comment
Share on other sites

The %~d0 will simply display the current drive, which may not be the CDROM.

Here is a batch file that will find all CDROMs and provide the environment variable of CD1, CD2, etc.:

@echo off

::::::::::::::::::::::::::
:: Title: GetCD.cmd ::
:: Author: Scr1ptW1zard ::
:: Date: 07/27/2007 ::
::::::::::::::::::::::::::

echo list vol>.\listvol.dp
setlocal enabledelayedexpansion
set CD=
for /f "tokens=3" %%a in ('diskpart /s .\listvol.dp^|find /i "-ROM"') do (
set /a count=!count! + 1
set CD!count!=%%a:)

:::::::::::::::::::::
:: Display CDROMs ::
:::::::::::::::::::::
:: NOTE:
:: Variables begin with "CD" followed by a number.
:: The number begins with 1 and increments to the total number of CDROMs

set cd

::::::::::::::::::::::::::::
:: Use CD# variables here ::
::::::::::::::::::::::::::::


endlocal

Hope this helps.

Link to comment
Share on other sites

Well Guys I am Blown away,

You certainly know your stuff on this forum, not that is a great recommendation coming from Lamer like Me, but it is a response of appreciation from ME - non the less!

The Variable within the Set CMD reports CDROM1=F: & CDROM2=G: along with other set variables. All I need to do now is instruct the user to insert the OS Install CD, allow it to spin up or use Horst Schaeffers dready as a check maybe, the variable with if exist will locate the inserted OS CD (With a files Check) then from a Wbat menu (front end) copy the files to a folder on my HDD to compile a bootable recovery console CD, the fileset is obtainable from within the Bootdisk\ folder on the OS Install CD.

I have acquired the Win2K Gold .IMG files (OEM) which reputedly by-passes any XP Logon password so this could be an option also.

Some could say why not use BartsPE or UBCD well yes but this is a quick small bootdisk varient that would replace the floppy Boot disk for the Recovery console as many PC users do not have a floppy drive anymore or floppies take an age to load. Batch files could also be written to try to repair the reg or copy files etc to removeable media from RConsole etc.

Barts & UBCD require quite a bit of setting up

This essentially is background info for this posting, thanks guys!

Regards,

ispy

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