Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FINDRAMD.exe (Win9X:) errorlevel H%%1 / (WinXP:) %%R:~%errorlevel%,1%%

367 views
Skip to first unread message

Benny Pedersen

unread,
Feb 28, 2004, 1:21:11 AM2/28/04
to
After I made a good boot disk that created a ramdrive, I would
also like to know what is the CDROM drive letter. Here is what I found:

NOTE: If you do not like line number 7 (cls &set R= ABC ...)
where Win95 do a CLS but would ignore the rest of the line,
then instead you can use this, (one line):
if Windows_NT==%OS% set R= ABCDEFGHIJKLMNOP
QRSTUVWXYZ&call %0 P %%R:~%errorlevel%,1%% [& goto:R

but the above line would do exactly the same as the one, used.

(Tested in both Win95 and WinXP.
Notice two long lines have to be unwrapped:
)

@echo off
if WinXP == WinX%1 set R=%2:&goto:eof

FINDRAMD.EXE
set R=[:

cls &set R= ABCDEFGHIJKLMNOPQRSTUVW
XYZ&call %0 P %%R:~%errorlevel%,1%% [& goto:R

for %%1 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 errorlevel H%%1 set R=%%1:

:R
if not (%R%) == ([:) echo. R is %R%
if (%R%) == ([:) echo. Failure.
for %%1 in ( echo. pause cls ) do %%1

:CleanUp
set R=

:eof


Benny Pedersen, http://2dos.homepage.dk
(not uploaded, Feb 28, 2004)
PS. In both Win95 and WinXP,
echo|find "E%[ Set Errorlevel=0 ]%">nul
would work.

I you have created a ramdrive, then your CDROM drive letter
maybe found after the ramdrive letter:

So put the following line before the label named CleanUp,
goto:CDR

And put the following lines in line number 3 (before FINDRAMD.EXE),
if not (%1)==(#) goto:Begin
:T
if not %2:.==%R%. if not %3.==. for %%1 in (shif goto:) do %%1t
set CDR=%3:
goto:eof
:CDR
call %0 # A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ [
if not (%CDR%) == ([:) echo. CDR is %CDR%
if (%CDR%) == ([:) echo. Failure.
for %%1 in ( echo. pause cls ) do %%1
set CDR=
goto:CleanUp
:Begin

BTW. For testing in some OS, you can (EX ramdrive=D) substitute
the line FINDRAMD.EXE with call SetErrorlevel 4
The file "SetErrorlevel.VBS" got one line, like this:
wScript.quit(wScript.arguments(0))

Here is (previous uploaded in this group) GetErrorlevel.BAT:

@echo off
FOR %%! IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL %%!0 SET E=%%!
FOR %%! IN (10 11 12 13 14 15 16 17 18 19 20 21 22 23 24) DO IF ERROR
LEVEL %%!0 SET E=%%!
FOR %%! IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL %E%%%! SET E=%E%%%!
FOR %%! IN (0 1 2 3 4 5) DO IF ERRORLEVEL 25%%! SET E=25%%!

ECHO. Errorlevel is %E%
pause
cls

Except the "SetErrorlevel.VBS", all code above should work in most OS.

Charles Dye

unread,
Feb 28, 2004, 10:33:52 AM2/28/04
to
On 27 Feb 2004 22:21:11 -0800, b.ped...@get2net.dk (Benny Pedersen)
wrote:

>After I made a good boot disk that created a ramdrive, I would
>also like to know what is the CDROM drive letter.

So did I. I came up with a couple of 4DOS approaches. One is
to use FINDRAMD.EXE, and massage its return code into a letter:

findramd.exe
iff errorlevel 255 then
unset /q ram
echo RAMdisk not found!
else
set ram=%@char[%@eval[%?+64]]:
echo RAMdisk is drive %ram
endiff

The second dispenses with FINDRAMD.EXE and simply searches for a
volume with the appropriate label; that's all FINDRAMD does anyway:

unset /q ram
do i = %@ascii[C] to %@ascii[Z]
set drv=%@char[%i]:
if %@ready[%drv] == 0 iterate
if %@removable[%drv] == 1 .or. %@cdrom[%drv] == 1 iterate
if "%@label[%drv]" == "ms-ramdrive" ( set ram=%drv %+ leave )
enddo
unset /q i drv
iff defined ram then
echo RAMdisk is drive %ram
else
echo RAMdisk not found!
endiff

--
Charles Dye ras...@highfiber.com

Message has been deleted

Joe Batch

unread,
Feb 29, 2004, 6:55:25 AM2/29/04
to

> The second dispenses with FINDRAMD.EXE and simply searches for a
> volume with the appropriate label; that's all FINDRAMD does anyway:
>
> unset /q ram
> do i = %@ascii[C] to %@ascii[Z]
> set drv=%@char[%i]:
> if %@ready[%drv] == 0 iterate
> if %@removable[%drv] == 1 .or. %@cdrom[%drv] == 1 iterate
> if "%@label[%drv]" == "ms-ramdrive" ( set ram=%drv %+ leave )
> enddo
> unset /q i drv
> iff defined ram then
> echo RAMdisk is drive %ram
> else
> echo RAMdisk not found!
> endiff


MS-DOS (not 4DOS) solution in two versions:

:: framd2.bat
@echo off
%1 %0 :: c d e f g h i j k l m n o p q r s t u v w x y z
set ramd=

:loop
shift
%comspec%/f/cvol %1: |find/i "ramdrive">nul
if errorlevel=1 if not "%2"=="" goto loop
if not errorlevel=1 set ramd=%1
if not "%ramd%"=="" echo. Ram drive is %ramd%
if "%ramd%"=="" echo. Ram drive not found


:: framd.bat
@echo off
if "%1"=="ReCuRs" goto loop (Recursion Handler)
set ramd=
%0 ReCuRs c d e f g h i j k l m n o p q r s t u v w x y z

:loop
shift
if "%1"=="" goto end
%comspec%/f/cvol %1: |find/i "ramdrive" >nul
if errorlevel=1 goto loop
set ramd=%1

:end
if not "%ramd%"=="" echo. Ram drive is %ramd%
if "%ramd%"=="" echo. Ram drive not found

Todd Vargo

unread,
Feb 29, 2004, 3:04:03 PM2/29/04
to

"Joe Batch" <joe_d...@yahoo.com> wrote:
>
> MS-DOS (not 4DOS) solution in two versions:
>
> :: framd2.bat
> @echo off
> %1 %0 :: c d e f g h i j k l m n o p q r s t u v w x y z

Hmm, I seem to recall some time ago, a frequent poster of this group was
complaining obsessively, about the practice of using of dynamic commenting
being too difficult for newcomers to grasp.

I wonder what pseudonym that poster is currently using, and if a change of
opinion may have occurred. (rhetorical thoughts) ;-)

--
Todd Vargo (remove hyphen to reply by email)

Joe Batch

unread,
Feb 29, 2004, 4:42:05 PM2/29/04
to

> > @echo off
> > %1 %0 :: c d e f g h i j k l m n o p q r s t u v w x y z

> ... the practice of using of dynamic commenting ...

> too difficult for newcomers to grasp.


This particular batch is really not difficult to grasp. You may
substitute the double colon [::] with [goto:loop] and it will
work just fine; except you will need to move the [set ramd=]
so it will not be skipped. You can also place [set ramd=] at
the beginning (just after :loop) of the loop module or section.

@echo off
set ramd=
%1 %0 goto:loop c d e f g h i j k l m n o p q r s t u v w x y z

:loop
shift
%comspec%/f/cvol %1: |find/i "ramdrive">nul
if errorlevel=1 if not "%2"=="" goto loop
if not errorlevel=1 set ramd=%1
if not "%ramd%"=="" echo. Ram drive is %ramd%
if "%ramd%"=="" echo. Ram drive not found


Or:

@echo off
%1
set ramd=
%0 goto:loop c d e f g h i j k l m n o p q r s t u v w x y z

:loop
shift
%comspec%/f/cvol %1: |find/i "ramdrive">nul
if errorlevel=1 if not "%2"=="" goto loop
if not errorlevel=1 set ramd=%1
if not "%ramd%"=="" echo. Ram drive is %ramd%
if "%ramd%"=="" echo. Ram drive not found


Above, the second design is more secure than the first, because
it will still run and do what it is supposed to do if a user
inadvertently enters a parameter or arguement (which is not
coincidently the name of a runnable program in the path) when
running it. Note: [%1] may also be placed before [@echo off]
since @echo off won't be needed the second time around.

The first example above will yield this result when entered
along with an inadvertent benign parameter:

Bad command or file name
Parameter format not correct - :
Ram drive not found


The second example above will yield this result when entered
along with an inadvertent benign parameter:

Bad command or file name
Ram drive is y


The version below will ignore inadvertent parameters; it is
extremely unlikely a user will choose "ReCuRs" a parameter.
To make it even more secure, add a character not allowed in
file names (as shown).

@echo off
if "%1"==":ReCuRs:" goto loop (Recursion Handler)
set ramd=

%0 :ReCuRs: c d e f g h i j k l m n o p q r s t u v w x y z

Joe Batch

unread,
Feb 29, 2004, 4:53:39 PM2/29/04
to

Another variation is:

@echo off
if "%1"==":ReCuRs:" for %%c in (shift goto:loop) do %%c (Recursion Handler)


set ramd=
%0 :ReCuRs: c d e f g h i j k l m n o p q r s t u v w x y z

:loop


%comspec%/f/cvol %1: |find/i "ramdrive" >nul

if not errorlevel=1 set ramd=%1
shift
if errorlevel=1 if not "%1"=="" goto loop

Todd Vargo

unread,
Feb 29, 2004, 10:25:26 PM2/29/04
to

"Joe Batch" <joe_d...@yahoo.com> wrote in message
news:EgvQAB$j...@conxion.com...

>
> > > @echo off
> > > %1 %0 :: c d e f g h i j k l m n o p q r s t u v w x y z
>
> > ... the practice of using of dynamic commenting ...
> > too difficult for newcomers to grasp.
>
> This particular batch is really not difficult to grasp.

IIRC, a certain batch pioneer was told differently years ago.

Message has been deleted
Message has been deleted

Joe Batch

unread,
Mar 2, 2004, 1:03:20 PM3/2/04
to
> This batch affords versatility by allowing easy checking of user
> specified drives. It suppresses error messages if drives are
> invalid. 'Esc' represents ASCII 27, created in edit by [Ctrl+P][Esc]
> and requires that ansi.sys or compatible is loaded.

A simpler and easier to use version of findramd.bat.

:: findramd.bat
@echo off
:: Written by Laurence Soucy on March 2, 2004
set ramd=
ctty nul
if "%1"==":" goto loop


%0 : c d e f g h i j k l m n o p q r s t u v w x y z

:loop
%comspec%/f/cvol %2: |find "RAMDRIVE">con
if not errorlevel=1 set ramd=%2
shift
if errorlevel=1 if not "%2"=="" goto loop
if "%ramd%"=="" echo. Ram drive not found>con
ctty con
%optional%echo Esc[2A
::

Supports user specified drive letters as shown.
findramd : e
findramd : h i j k

Default use will check all drives.
findramd

0 new messages