Originally posted by ljb603 at 2008-7-14 18:09:
下面是我对硬盘 MBR 操作一个批处理,这样写对吗?(特别是每项的返回码是否正确):
@echo off
cls
echo.
echo 硬盘 MBR 操作选项:
echo.
echo ...
操纵成功返回0,不成功返回值大于0,见一楼。
在你的批处理中如果失败会显示失败信息,在显示成功信息。
@echo off
cls
echo.
echo 硬盘 MBR 操作选项:
echo.
echo 1.备份 2.恢复 3.重建
echo.
echo 4.查看 5.清零 6.退出
echo.
choice /c:123456 /n 我要:
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 读取0柱1扇区的MBR失败!
if errorlevel 1 goto Exit
dspt 0 35 1 /r %ramdrive%\mbr.bak /y >nul
if errorlevel 1 echo 备份MBR到0柱35扇区失败!
if errorlevel 0 echo 恭喜你,操作成功!!!
goto Exit
:dspt2
cls
dspt 0 35 1 /s %ramdrive%\mbr.res /y >nul
if errorlevel 1 echo 读取0柱35扇区的MBR失败!
if errorlevel 1 goto Exit
dspt 0 0 1 /r %ramdrive%\mbr.res /y >nul
if errorlevel 1 echo 恢复硬盘 MBR 失败!
if errorlevel 0 echo 恭喜你,操作成功!!!
goto Exit
=========================
如果没有备份MBR岂不是MBR被清除!这样你会损失惨重的
=========================
:dspt3
cls
dspt 0 /mbr /noback /y >nul
if errorlevel 1 echo 重建硬盘 MBR 失败!
if errorlevel 0 echo 恭喜你,操作成功!!!
goto Exit
:dspt4
cls
dspt 0 0 1 /e /y >nul
if errorlevel 1 echo 硬盘 MBR 清零失败!
if errorlevel 0 echo 恭喜你,操作成功!!!
goto Exit
=============================
从最开始显示的看好像应该是查看,而不是清除,如果有人选择了4,岂不是MBR被清除,原来本打算看一下的,弄不好会丢失硬盘数据的,应该认真一定吧
=================================
:dspt5
cls
dspt 0 35 1 /L /p /a
if errorlevel 1 echo 你没有备份 MBR !
if errorlevel 0 echo 恭喜你,操作成功!!!
goto Exit
======================================
如果选择了5,应该是清除,不过显示到时不会造成破坏
如果显示第一硬盘MBR,请使用 dspt 0 0 1 /l /p /a
如果显示备份请用你的这段代码
======================================
:Exit
Last edited by 19951001 on 2008-7-14 at 10:06 PM ]
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 ]