Originally posted by ljb603 at 2008-7-14 18:09:
The following is a batch script I wrote for operating the hard disk MBR. Is it correct? (Especially whether the return codes of each item are correct):
@echo off
cls
echo.
echo Hard disk MBR operation options:
echo.
echo ...
Operation is successful returns 0, and unsuccessful returns a value greater than 0, see the first floor.
In your batch script, if it fails, it will display a failure message, and if it succeeds, it will display a success message.
@echo off
cls
echo.
echo Hard disk MBR operation options:
echo.
echo 1. Backup 2. Restore 3. Rebuild
echo.
echo 4. View 5. Clear 6. Exit
echo.
choice /c:123456 /n I want:
if errorlevel 6 goto Exit
if errorlevel 5 goto dspt5
if errorlevel 4 goto dspt4
if errorlevel 3 goto dspt3
if errorlevel 2 goto dspt2
if errorlevel 1 goto dspt1
:dspt1
cls
dspt 0 0 1 /s %ramdrive%\mbr.bak /y >nul
if errorlevel 1 echo Failed to read MBR of cylinder 0, sector 1!
if errorlevel 1 goto Exit
dspt 0 35 1 /r %ramdrive%\mbr.bak /y >nul
if errorlevel 1 echo Failed to backup MBR to cylinder 0, sector 35!
if errorlevel 0 echo Congratulations, operation succeeded!!!
goto Exit
:dspt2
cls
dspt 0 35 1 /s %ramdrive%\mbr.res /y >nul
if errorlevel 1 echo Failed to read MBR of cylinder 0, sector 35!
if errorlevel 1 goto Exit
dspt 0 0 1 /r %ramdrive%\mbr.res /y >nul
if errorlevel 1 echo Failed to restore hard disk MBR!
if errorlevel 0 echo Congratulations, operation succeeded!!!
goto Exit
=========================
If there is no backup of MBR, then the MBR will be cleared! This will cause you great losses
=========================
:dspt3
cls
dspt 0 /mbr /noback /y >nul
if errorlevel 1 echo Failed to rebuild hard disk MBR!
if errorlevel 0 echo Congratulations, operation succeeded!!!
goto Exit
:dspt4
cls
dspt 0 0 1 /e /y >nul
if errorlevel 1 echo Failed to clear hard disk MBR!
if errorlevel 0 echo Congratulations, operation succeeded!!!
goto Exit
=============================
From the initial display, it seems it should be View, not Clear. If someone selects 4, then the MBR will be cleared. Originally intended to just view, but it might lose hard disk data. Should be careful
=================================
:dspt5
cls
dspt 0 35 1 /L /p /a
if errorlevel 1 echo You have not backed up MBR!
if errorlevel 0 echo Congratulations, operation succeeded!!!
goto Exit
======================================
If 5 is selected, it should be Clear, but the display won't cause damage at that time
If you want to display the first hard disk MBR, use dspt 0 0 1 /l /p /a
If you want to backup, use your this code
======================================
:Exit
[
Last edited by 19951001 on 2008-7-14 at 10:06 PM ]