Windows bat 脚本给文件夹加密
686人浏览 / 0人评论
lock.bat
@echo off & title 加解密我的密盘 By 风仔
color 0a & mode 50,8
::设置解锁后的密盘名字
set Folder=我的密盘
::设置加锁后的密盘名字
set LockFolder=Secret Disk Locker
::以下为代码主执行区域,请勿随意修改,以免运行出错。
for %%a in (%sfxcmd%) do cd /d "%%~dpa"
set "LockFolder=%LockFolder%.{00021401-0000-0000-C000-000000000046}"
set "FU=..FOLDER UNLOCKED.."
set "FL=..FOLDER LOCKED.."
set "Cfg=LockConfig.cfg"
if exist "%Folder%" (
if not exist "%Folder%\%FU%\%Cfg%" goto SettingPass
goto Confirm
) else (
if exist "%LockFolder%" (
if not exist "%LockFolder%\%FL%\%Cfg%" goto Warning
goto Unlock
) else (
goto MdLocker
)
)
:Confirm
cls & echo,
::echo 您确定要加密“%Folder%”吗?(Y/N)
::set /p "Cho=>"
::if /i "%Cho%"=="Y" goto Lock
goto Lock
::if /i "%Cho%"=="N" exit
::echo, & echo 无效选择,请重新输入。
call :Delay "2" "Confirm"
:Lock
ren "%Folder%" "%LockFolder%"
call :State "%FL%" "%FU%"
attrib +h +s "%LockFolder%"
echo, & echo “%Folder%”已加锁。
call :Delay "2" "End"
:Unlock
for /f "delims=" %%a in ('type "%LockFolder%\%FL%\%Cfg%"') do set "%%~a"
set "Count=%Coun%"
if not %Lock% equ 0 goto CheckLimit
:InputPass
cls & echo,
echo 请输入密码来解锁(%Count% 次机会):
set /p "Password=>"
if not "%Password%"=="%Pass%" goto Fail
call :State "%FU%" "%FL%"
attrib -h -s "%LockFolder%"
ren "%LockFolder%" "%Folder%"
echo, & echo “%Folder%”已成功解锁。
call :Delay "3" "Open"
:Fail
set /a Count-=1
if %Count% leq 0 (
goto LockInput
) else (
echo, & echo 无效密码,请重新输入。
)
call :Delay "2" "InputPass"
:LockInput
set /a MM=%Inte%+%time:~3,2%
set "HH=%time:~,2%"
set "HH=%HH: =%"
call :GetDATE 0
if %MM% geq 60 (
set /a MM-=60
set /a HH+=1
)
if %MM% lss 10 set "MM=0%MM%"
if %HH% geq 24 (
set "HH=0"
call :GetDATE 1
)
if %HH% lss 10 set "HH=0%HH%"
set "Rema=%Rdt%%HH%%MM%"
call :CreatCfg "%Pass%" "%Coun%" "%Inte%" "1" "%Rema%" "%LockFolder%\%FL%"
:InputLock
cls & color 0c & echo,
echo 密码多次输入错误,已限制解锁。& echo,
echo 请在 %Rema:~,4%/%Rema:~4,2%/%Rema:~6,2% %Rema:~8,2%:%Rema:~-2% 以后再尝试解锁。
call :Delay "5" "End"
:CheckLimit
set "NowTime=%time:~,2%%time:~3,2%"
call :GetDATE 0
set "NowTime=%Rdt%%NowTime: =0%"
if '%Rema%' gtr '%NowTime%' goto InputLock
call :CreatCfg "%Pass%" "%Coun%" "%Inte%" "0" "0" "%LockFolder%\%FL%"
goto Unlock
:MdLocker
md "%Folder%"
echo “%Folder%”创建成功。
:SettingPass
echo, & echo 设置“%Folder%”解锁密码(默认 admin)
set /p "Pass=>"
if not defined Pass set "Pass=admin"
cls & echo, & echo 设置密码尝试次数(默认 3 次)
set /p "Coun=>"
if not defined Coun set "Coun=3"
echo %Coun%|findstr "^[0-9]*$" >nul || set "Coun=3"
if %Coun% lss 1 set "Coun=1"
cls & echo, & echo 设置密码多次输入错误后的解锁限制间隔
echo (1 - 59 分钟,默认 30 分钟)
set /p "Inte=>"
if not defined Inte set "Inte=30"
echo %Inte%|findstr "^[0-9]*$" >nul || set "Inte=30"
if %Inte% geq 1 (
if %Inte% gtr 59 (
set "Inte=30"
)
) else set "Inte=30"
md "%Folder%\%FU%\"
cls & echo “%Folder%”& echo,
echo 解锁密码为 %Pass%
echo 密码尝试为 %Coun% 次
echo 错误间隔为 %Inte% 分钟
echo, & echo 请务必牢记密码,按任意键继续。
call :CreatCfg "%Pass%" "%Coun%" "%Inte%" "0" "0" "%Folder%\%FU%"
pause>nul
goto Confirm
:Warning
mode 45,5 & cls & echo, & color 0c
echo “%Folder%”解锁配置异常或非本工具创建的。
echo 因此无法对其进行解锁操作,请更换目录重建。
call :Delay "6" "End"
:CreatCfg
(echo Pass=%~1
echo Coun=%~2
echo Inte=%~3
echo Lock=%~4
echo Rema=%~5)>"%~6\%Cfg%"
echo,>"%~6\请勿删除此目录中的文件"
(echo @echo off ^& title 解除防删模式 By 风仔
echo color 0a ^& mode 80,3 ^& echo,
echo echo 防删模式已解除(密码功能失效),现在可以正常删除“%Folder%”了。
echo rd /s /q "..FOLDER LOCKED..\" "..FOLDER UNLOCKED..\" 2^>NUL
echo ping 127.0.0.1 -n "4"^>nul
echo start "" /min cmd /c del /f /q "%%~0"
echo exit)>"%~6\..\unlock.bat"
goto :eof
:State
md "%LockFolder%\%~1\" 2>nul
type "%LockFolder%\%~2\%Cfg%">"%LockFolder%\%~1\%Cfg%"
rd /s /q "%LockFolder%\%~2\"
echo,>"%LockFolder%\%~1\请勿删除此目录中的文件"
goto :eof
:GetDATE
echo WScript.Echo DatePart("yyyy",DateAdd("d",+%~1,date)) ^& Right("0" ^& DatePart("m",DateAdd("d",+%~1,date)),2) ^& Right("0" ^& DatePart("d",DateAdd("d",+%~1,date)),2)>"%tmp%\GetDATE.vbs"
for /f "delims=" %%a in ('cscript /nologo "%tmp%\GetDATE.vbs"') do set "Rdt=%%~a"
del "%tmp%\GetDATE.vbs"
goto :eof
:Delay
ping 127.0.0.1 -n "%~1">nul
goto %~2
:Open
start "" "%Folder%"
:End
exit
全部评论