Jump to content











Photo
- - - - -

Finding cdroms and ramdrives


  • Please log in to reply
1 reply to this topic

#1 wendy

wendy

    Frequent Member

  • Lady
  • 268 posts
  • Location:one mile from the QR main line
  • Interests:Operating systems, Weights and Measures, Geometry
  •  
    Australia

Posted 21 February 2013 - 11:23 AM

One can find cdroms and ramdrives, using regina rexx (eg the latest version).  This code is quite flexible, and will even go to looking for the next drive etc.  It gives a number of outputs, which might be tested in different ways.  It's the sort of utility people look for.

 

regina  cdrom.rex [c|r][drive]  $string 

 

c searches for cdroms from drive+1

r searches for ramdrives from drive+1

drive defaults to ' ', which gives drive+1 = a

 

$ is any character.  If it's an '@' then different magic happens

The character $ is replaced by the found drive without a colon, etc, eg S

When you use @, the string is @string=value,  where @ is replaced in the value.

You can use the redirected batch or error-level tests to find the drive.

 

eg 

 

   >regina cdrom r $Your ramdrive is in drive $: 

   < Your ramdrive is in drive R:

 

This batch will set cdrom0, cdrom1, cdrom2, and ramd in the current environment, to the first, second and third cdrom,  (if they exist), and the ramd if it exists.

 

regina cdrom c @cdrom0=@: > temp.bat
call temp.bat
if errorlevel 1 regina cdrom c%cdrom0% @cdrom1=@: >> temp.bat
call temp.bat
if errorlevel 1 regina cdrom c%cdrom1: @cdrom2=@: >> temp.bat
call temp.bat
regina cdrom r @ramd=@: >> temp.bat
call temp.bat

 

It needs inline help, yet.  But it's way ahead of most things.

 

 

/* REXX find cdrom */
/* Wendy Krieger - an OS2 fan 2 */
call rxfuncadd 'sysloadfuncs', 'rexxutil', 'sysloadfuncs' ; call sysloadfuncs
numeric digits 20 ;
parse arg opt string
opt = changestr('/-:', opt, '   '); opt = strip(opt)
parse upper var opt with 1 kind 2 drive 3 .
if kind = 'C' then kind = 'CDROM'
if kind = 'R' then kind = 'RAMDISK'
if drive='' then drive=' '; drive = d2c(c2d(drive)+1)
gamma = SysDriveMap(drive, kind)
gamma = left(gamma, 1)
if gamma = '' then gamma = ' ' ; erl = c2d(gamma) // 32
parse var string 1 letter 2 string
string = changestr(letter, string, gamma)
if letter='@' then do
  parse var string environ'='newstr
  if erl = 0 then newstr= ''
  aa = value( environ, newstr, 'SYSTEM')
  call lineout, 'set' environ'='newstr ; end
else if erl > 0 then call lineout, string
exit erl

 

You need to download regina 3.5 or later.   3.6 needs xp or later, but 3.5 runs under older versions, as does 3.7.

 

From the regina distro, the files used are

 

regina.exe   regina.dll   rexxutil.dll.   

 

Copy these to a directory in the path.



#2 wendy

wendy

    Frequent Member

  • Lady
  • 268 posts
  • Location:one mile from the QR main line
  • Interests:Operating systems, Weights and Measures, Geometry
  •  
    Australia

Posted 22 February 2013 - 08:09 AM

This is commented code, for what matters.

 

/* REXX find cdrom */
/* Wendy Krieger - an OS2 fan 2 */
call rxfuncadd 'sysloadfuncs', 'rexxutil', 'sysloadfuncs' ; call sysloadfuncs
numeric digits 20 ;
parse arg opt string   /* first word + rest of tail */
opt = changestr('/-:', opt, '   '); opt = strip(opt)    /* remove -, /, etc from opt */
parse upper var opt with 1 kind 2 drive 3 .     /* get kind of drive, and where to start */
if kind = 'C' then kind = 'CDROM'
if kind = 'R' then kind = 'RAMDISK'
if drive='' then drive=' '; drive = d2c(c2d(drive)+1)   /* If the user says c: we look for d: and larger */
gamma = SysDriveMap(drive, kind)    /*  get the next drive */
gamma = left(gamma, 1)    /*  loose the colon */
if gamma = '' then gamma = ' ' ; erl = c2d(gamma) // 32    /* errorlevels:  A=a=1, B=b=2, C=c=3, etc */
parse var string 1 letter 2 string     /*  here, for $cdrom=$: , the prog reads the first $, and replaces later $ with the letter desired */
string = changestr(letter, string, gamma)  /*  this is the replacement */
if letter='@' then do    /* magic for processing environments */
  parse var string environ'='newstr
  if erl = 0 then newstr= ''
  aa = value( environ, newstr, 'SYSTEM')   /* works in 4nt, not in cmd */
  call lineout, 'set' environ'='newstr ; end     /* still produces SET environ=value */
else if erl > 0 then call lineout, string   /* print the string if there is a drive */
exit erl   /* return a value for ERRORLEVEL:  A=a=1, B=b=2, etc  */

 

When one looks for a cdrom, one can not suppose that the first cdrom is the real one, or that it's the interesting one.  Suppose that you have the hardware cdrom in S: (where OS/2 puts it).  Now.  You might have programs like virtualcd that can mount an iso at a different position(s) (say O: and E: or whatever).

 

So if you look for the first cdrom, you will get E: in this example.  This is not the disk you might be looking for, so you search again, for a letter, like 'O'.  This program allows you to do this, by "cdrom.rex c%cdrom% @cdrom=@:  "   Because the search begins at %cdrom% (ie E:), it produces the next result F or later.  It will give then O: next.  A further search reveals the correct drive S:.   This is why i included the 'search from' thing.

 

The second bit is about getting the environment letter.  The script attempts to set the current environment.  In 4nt, it works, the value is set directly.  However, in cmd, it sets the environment that regina inherits, but is not passed back to cmd's environment.  This is why we have to do things like produce a redirectable string.  An environment value is created for redirection to a batch file, which can then be called.   If there is no further drive, the line is produced with a null value, eg "SET CDROM=".  This removes the value from the environment.

 

Error levels are supported, so if there is no drive reported, one gets an errorlevel of 0.  Otherwise, the errorlevel is the drive number, in line with the DOS findcd and findram utilities. 

 

One could add support for other kind of drives, like removable (not cdrom), fixed drives etc.  This just amounts to adding an extra letter at 'if kind= 'M' then kind='REMOVABLE'  etc.  This is documented in the SysDriveMap command in the .PDF.  Searching for removable drives might detect floppy disks and usbs if these are seen as removable.

 

You can register .rex scripts in the PATHEXT.  If you use rexx a lot, it's quite useful.  Patrick McPhee's W32UTILS is a welcome extension that gives regina access to the registry, including loading and unloading things, creating icons, etc.  You could, for example, use it to create a desktop from a single script similar to this.

 

I have a script, of slightly different nature, using Frank P Westlake's excelent utility conset.exe.  This utility will read things from registry into the current environment.  This script, allows you to change to some shellfolder directory (similar to typing shell:folder in the run dialog).  So, eg cdf desktop will change to the desktop.

 

You can use the same thing to open your own folders, or if you mount a foreign registry in the same position, to its folders. Note that i add my own shell-folders at "HKLM\Software\Wendy\Folders".  So "cdf batch" changes to the batch folder.

 

You can open the file in registry too, with the /m(achine), /u(ser) and /w(endy) switches.  The reg: protocol can be handled either by Sysinterns 'regjump' utility, or the 'regmagik' program. 

 

@echo off
:: cd shell folder.
set zdir=
set zshf=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
set zcmd=chdir
set zhere=%*
if "%1"=="/o" set zcmd=open
if "%1"=="/o" set zhere=%zhere:~3%
conset /q /k zdir=HKLM\%zshf%\%zhere%
if not "%zdir%"=="" goto :doit
conset /q /k zdir=HKCU\%zshf%\%zhere%
if not "%zdir%"=="" goto :doit
conset /q /k zdir=HKLM\Software\Wendy\Folders\%zhere%
if not "%zdir%"=="" goto :doit
if /i "%1"=="/m" goto :hklm
if /i "%1"=="/u" goto :hkcu
if /i "%1"=="/w" goto :hkwe
goto :end
:hklm
shelexec reg:hklm\%zshf%
goto :end
:hkcu
shelexec reg:hkcu\%zshf%
goto :end
:hkwe
shelexec reg:hklm\software\wendy\folders
goto :end
:doit
set zcxm=
if %zcmd%==chdir cd /d %zdir%
if %zcmd%==open shelexec %zdir%
set zdir=
:end

 

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users