Understanding of the setramd.bat command line. If there are any mistakes, please correct them, masters!
@echo off
a:\findramd
:: Run findramd in drive a to find the virtual drive.
if errorlevel 255 goto no_ramdrive
:: If the return value of executing findramd is 255, it means there is no virtual drive. Then execute no_ramdrive to display the information that the virtual drive does not exist.
if not errorlevel 3 goto no_ramdrive
:: If the return value of executing findramd is not 3 (when the return value is 3, the virtual drive exists), it means there is no virtual drive. Then execute no_ramdrive to display the information that the virtual drive does not exist.
goto do_shift
:: If the above two situations do not hold (indicating that the virtual drive exists), then execute do_shift to start setting the drive letter of the virtual drive.
:loop
:: Determine the drive letter of the virtual drive.
if errorlevel %1 goto no_shift
:: Because after shift is executed, the return value is the value represented by parameter %1. If the value represented by parameter %1 can be returned as the return value, it means that parameter %1 is not empty. Then execute no_shift to assign a drive letter to the virtual drive.
:do_shift
:: Start setting the drive letter of the virtual drive.
set cdrom=%2
:: Set the string cdrom (the drive letter of the CD-ROM. Determined by mscdex /L:%cdrom%) corresponding to parameter %2. Please note: At this time, the drive letter assigned to the CD-ROM is determined by the hardware and does not include the virtual drive established by ramdrive. Because the default drive letter allocation of the system is: floppy drive (a), floppy drive (b), hard disk, CD-ROM. So, if there is only one partition on the hard disk, the hard disk (c), CD-ROM (d). If there are multiple partitions on the hard disk, the CD-ROM drive letter is pushed back. If there is no hard disk, the CD-ROM (c). When there is a virtual drive, the virtual drive is arranged between the hard disk and the CD-ROM, so the CD-ROM drive letter will be moved back by one position.
shift
:: Shift the parameters by one position to the left (that is, make the drive letters corresponding to parameters %1 and %2 move forward by one position).
shift
:: Shift the parameters by one position to the left (that is, make the drive letters corresponding to parameters %1 and %2 move forward by one position again).
if not %1*==* goto loop
:: After two left shifts, if parameter %1 is still not empty (that is, %1*==* is not established), it means the virtual drive exists. Then execute loop to determine the drive letter of the virtual drive.
goto no_ramdrive
:: After two left shifts, if parameter %1 is empty (that is, %1*==* is established), it means the virtual drive does not exist. Then execute no_ramdrive to display the information that the virtual drive does not exist.
:no_shift
:: Assign a drive letter to the virtual drive.
set ramd=%2
:: Let the drive letter of the virtual drive take the drive letter corresponding to parameter %2 (that is, the drive letter that the CD-ROM obtained before the virtual drive was established).
goto success
:: Execute success to display the information that the virtual drive is successfully established.
:no_ramdrive
:: No virtual drive exists or cannot be established (some prompt information can be set).
:success
:: Display the information that the virtual drive is successfully established
@echo off
a:\findramd
:: Run findramd in drive a to find the virtual drive.
if errorlevel 255 goto no_ramdrive
:: If the return value of executing findramd is 255, it means there is no virtual drive. Then execute no_ramdrive to display the information that the virtual drive does not exist.
if not errorlevel 3 goto no_ramdrive
:: If the return value of executing findramd is not 3 (when the return value is 3, the virtual drive exists), it means there is no virtual drive. Then execute no_ramdrive to display the information that the virtual drive does not exist.
goto do_shift
:: If the above two situations do not hold (indicating that the virtual drive exists), then execute do_shift to start setting the drive letter of the virtual drive.
:loop
:: Determine the drive letter of the virtual drive.
if errorlevel %1 goto no_shift
:: Because after shift is executed, the return value is the value represented by parameter %1. If the value represented by parameter %1 can be returned as the return value, it means that parameter %1 is not empty. Then execute no_shift to assign a drive letter to the virtual drive.
:do_shift
:: Start setting the drive letter of the virtual drive.
set cdrom=%2
:: Set the string cdrom (the drive letter of the CD-ROM. Determined by mscdex /L:%cdrom%) corresponding to parameter %2. Please note: At this time, the drive letter assigned to the CD-ROM is determined by the hardware and does not include the virtual drive established by ramdrive. Because the default drive letter allocation of the system is: floppy drive (a), floppy drive (b), hard disk, CD-ROM. So, if there is only one partition on the hard disk, the hard disk (c), CD-ROM (d). If there are multiple partitions on the hard disk, the CD-ROM drive letter is pushed back. If there is no hard disk, the CD-ROM (c). When there is a virtual drive, the virtual drive is arranged between the hard disk and the CD-ROM, so the CD-ROM drive letter will be moved back by one position.
shift
:: Shift the parameters by one position to the left (that is, make the drive letters corresponding to parameters %1 and %2 move forward by one position).
shift
:: Shift the parameters by one position to the left (that is, make the drive letters corresponding to parameters %1 and %2 move forward by one position again).
if not %1*==* goto loop
:: After two left shifts, if parameter %1 is still not empty (that is, %1*==* is not established), it means the virtual drive exists. Then execute loop to determine the drive letter of the virtual drive.
goto no_ramdrive
:: After two left shifts, if parameter %1 is empty (that is, %1*==* is established), it means the virtual drive does not exist. Then execute no_ramdrive to display the information that the virtual drive does not exist.
:no_shift
:: Assign a drive letter to the virtual drive.
set ramd=%2
:: Let the drive letter of the virtual drive take the drive letter corresponding to parameter %2 (that is, the drive letter that the CD-ROM obtained before the virtual drive was established).
goto success
:: Execute success to display the information that the virtual drive is successfully established.
:no_ramdrive
:: No virtual drive exists or cannot be established (some prompt information can be set).
:success
:: Display the information that the virtual drive is successfully established
