标题: [文件操作] [分享]批处理版undel实现数据安全删除、恢复 [打印本页]
作者: bat_fan 时间: 2010-3-18 22:30 标题: [分享]批处理版undel实现数据安全删除、恢复
简单说明:undelete命令能恢复del命令删除了的文件
不足之处:对个人隐私、机密信息有不小隐患。(Microsoft处于安全考虑,这类“高危”命令几乎都精简掉了。)
优点 :undo、后悔药之功效。
吹捧的话就不说了,简言之,小巧易用。
已测试系统:Win 7 旗舰7600 + Windows XP Mode
包组成:mydel.bat、undel.bat、mdel.bat(欢迎自行转换成其他格式,如exe)
mydel.bat:删除一(多)个文件,慎用通配符[只能匹配第一个,如果存在]。
undel.bat:恢复用mydel命令删除的文件,不支持引号。
mdel.bat:mydel.bat的封装,实现带通配符的某一特征的文件类删除。(mode_del之意)
且看代码
mydel.bat- @echo off & setlocal ENABLEEXTENSIONS
- ::Made by [D.S.T] lnxxey 21:51 2010/2/3
- ::暂时还不支持直接跟带有空格的路径。
- ::即,参数必须是一个整体。
- ::另外传递的参数中引号不要超过一对。
- if /i "%1" equ "" goto out
- :start
- if /i "%1" equ "-d" del /a /q /f \\.\d:\undel\del_backup.txt >nul 2>nul && goto ok
- set all=%1
- if /i "%all:~1,1%" equ ":" goto whole
- if /i "%all:~2,1%" equ ":" goto whole
- if exist "%cd%%1" cacls "%cd%%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%cd%%1" >nul 2>nul & icacls "%cd%%1" /grant Administrator:(F,WDAC) >nul 2>nul
- if /i "%cd:~-1,1%" equ "\" (
- dir /a-d "%cd%%1" >nul 2>nul || goto bad
- )
- if exist "%cd%\%1" cacls "%cd%\%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%cd%\%1" >nul 2>nul & icacls "%cd%\%1" /grant Administrator:(F,WDAC) >nul 2>nul
- if /i "%cd:~-1,1%" neq "\" (
- dir /a-d "%cd%\%1" >nul 2>nul || goto bad
- )
- for /f "delims= tokens=*" %%i in ('echo %1') do set name=%%~nxi& set allf=%%~fi
- if exist "%1" cacls "%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%1" >nul 2>nul & icacls "%1" /grant Administrator:(F,WDAC) >nul 2>nul
- attrib -s -r -h %1 >nul
- move /y "%1" d:\undel\"%name%_lnxxey" >nul 2>nul && echo %allf%已成功删除...
- ::copy /y "%1" d:\undel\"%name%_lnxxey" >nul
- ::erase /a /q /f %1 >nul 2>nul && echo %allf%已成功删除...
- if /i "%cd:~-1,1%" equ "\" (
- echo "%cd%%1"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
- ) else (
- echo "%cd%\%1"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
- )
- ::echo "%allf%"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
- :ok
- shift /1
- if not "%1"=="" goto start
- echo 操作已完成!
- goto out
- :whole
- dir /a-d "%1" >nul 2>nul || goto bad
- cacls "%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%1" >nul 2>nul & icacls "%1" /grant Administrator:(F,WDAC) >nul 2>nul
- for /f "delims= tokens=*" %%i in ('echo %1') do set name=%%~nxi& set allf=%%~fi
- attrib -s -r -h %1 >nul
- move /y "%1" d:\undel\"%name%_lnxxey" >nul 2>nul && echo %allf%已成功删除...
- ::copy /y "%1" d:\undel\"%name%_lnxxey" >nul
- ::erase /a /q /f %1 >nul 2>nul && echo %allf%已成功删除...
- echo "%1"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
- goto ok
- :bad
- echo 要删除的文件不存在!
- shift /1
- if not "%1"=="" goto start
- :out
复制代码
undel.bat- @echo off & setlocal ENABLEEXTENSIONS
- ::Made by [D.S.T] lnxxey 21:51 2010/2/3
- ::参数不要使用任何引号
- if /i "%1" equ "" goto out
- :start
- dir /ad d:\undel\del_backup.txt >nul 2>nul && goto **
- if not exist d:\undel\del_backup.txt goto fileNexist
- if /i "%1" equ "-d" del /a /q /f \\.\d:\undel\del_backup.txt >nul 2>nul &if not exist "d:\undel\del_backup.txt" echo 中转记录用文件已删除... & goto ok
- if /i "%1" equ "-l" goto list
- if /i "%1" equ "-a" for /f "delims=# tokens=1,2" %%i in (d:\undel\del_backup.txt) do (
- if /i "%%i" neq "" (
- move /y %%j %%i >nul 2>nul && echo 已恢复%%i
- ))
- if /i "%1" equ "-a" goto ok
- type d:\undel\del_backup.txt|find /i "%1" >nul 2>nul || goto bad
- for /f "delims=# tokens=1,2" %%i in ('type d:\undel\del_backup.txt ^|find /i "%1" 2^>nul') do (
- if /i "%%i" neq "" (
- move /y %%j %%i >nul 2>nul && echo 已恢复%%i
- ))
- goto ok
- :bad
- echo 要恢复的文件不存在或文件名错误!注意不要使用引号...
- :ok
- shift /1
- if not "%1"=="" goto start
- goto out
- :**
- set /p you=看来你是存心搞怪,是否将搞怪进行到底[Y/N]:
- if /i "%you%" equ "Y" echo 此次文件恢复未成功... && goto out
- if /i "%you%" equ "N" rd /q /s \\.\d:\undel\del_backup.txt >nul 2>nul && echo 搞怪文件夹已经放倒... && goto start
- echo.
- echo 输入有错误,请重新输入...
- echo.
- goto **
- :fileNexist
- echo 中转用文件暂时不存在,删除文件请使用mydel命令。
- :out
- echo 操作已完成!
- goto :eof
-
- :list
- >d:\undel\sort.txt sort<d:\undel\del_backup.txt
- copy /y d:\undel\sort.txt d:\undel\test.txt >nul 2>nul
- cd.>d:\undel\much.txt
- setlocal enabledelayedexpansion
- for /f "tokens=*" %%i in (d:\undel\sort.txt) do (
- set first=!second!
- set second=!third!
- set third=%%i
- call :comp_
- )
- if not ""%second%=="" if ""%second%==""%third% >>d:\undel\much.txt echo %third%
- findstr . d:\undel\much.txt>nul||(del /a /f /q d:\undel\much.txt & goto result)
- for /f "delims=# tokens=1,2" %%i in (d:\undel\much.txt) do (
- set aa=%%~nxi
- find /v "!aa!" d:\undel\test.txt>>d:\undel\tmp.txt
- del /q /a /f d:\undel\test.txt
- ren d:\undel\tmp.txt test.txt
- )
- :result
- type d:\undel\much.txt>>d:\undel\test.txt && del /a /q /f d:\undel\much.txt
- for /f "delims=# tokens=1,2" %%i in (d:\undel\test.txt) do (if exist %%j echo 文件%%i可恢复)
- goto ok
- :comp_
- if not ""%first%=="" (
- if not ""%second%=="" (
- if ""%second%==""%first% (
- if not ""%second%==""%third% >>d:\undel\much.txt echo %second%
- )
- )
- )
- goto :eof
复制代码
mdel.bat- @echo off & setlocal ENABLEEXTENSIONS
- :start
- if /i ""%1 equ "" goto out
- for /f "delims= tokens=*" %%i in ('echo %1') do set filedp=%%~dpi
- for /f "delims= tokens=*" %%i in ('dir /a-d /b %1') do @if /i "%%i" neq "" call my_del "%filedp%%%i"
- shift /1
- goto start
- :out
- echo mdel运行完成...
复制代码
作者: BatCoder 时间: 2010-3-19 00:21
实际就是用文件夹来代替类似回收站的功能,对吧。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |