BATCH:阻止某人使用CTRL c或CTRL BREAK绕过我的密码脚本

时间:2016-04-30 08:04:56

标签: batch-file cmd break

@echo off
:home
cd c:/
IF EXIST "%PROGRAMFILES(X86)%" (set bit=x64) ELSE (set bit=x86)
title Log in to CMD
color f0
cls
echo.
echo              Cmd Accounts
echo ======================================
echo.
echo [1]  Log In  (access existing Account)
echo.
echo [2]  Register (add an account)
echo.
echo [3]  Delete Account (remove an account)
echo.
echo ============Ethans Security===========
echo.
set RegisterVal=0
set DeleteAcc=0
set /p op=
if %op%==1 goto Login
if %op%==2 goto setReg
if %op%==3 goto setDel
goto home
:setReg
set RegisterVal=1
goto Login
:setDel
set DeleteAcc=1
goto Login
:Login
cls
cd c:/
mkdir enxlogin
cd enxlogin
cls
echo              Cmd Login
echo ======================================
echo.
set /p logName="Enter your username:"
EditV64 -m -p 'Enter your Password:' logPass
EditV32 -m -p 'Enter your Password:' logPass
if exist %logName%.txt goto continue
cls
color fc
echo              Cmd Login
echo ======================================
echo.
echo Acces Denied
pause
goto home
:continue
set /p var= <%logName%.txt
set actPass=%var%
call enx actPass actPass
if %logPass%==%actPass% goto logdone
color fc
cls
echo              Cmd Login
echo ======================================
echo.
echo Acces Denied
pause
goto home
:Register
cd c:/
mkdir enxlogin
cd enxlogin
cls
echo              Cmd Register
echo ======================================
echo.
set /p regName="Enter new username:"
set /p regPass="Enter new password:"
set regName=%regName%
set regPass=%regPass%
call enx regPass regPass
echo %regPass%>%regName%.txt
set regName=NUL
set regPass=NUL
cls
echo             Cmd Register
echo ======================================
echo.
echo Acount Successfully Created
echo.
pause
goto home
:DelAccount
cd c:/
mkdir enxlogin
cd enxlogin
cls
echo            Cmd Delete Account
echo ======================================
echo.
echo Account List
echo ------------
for %%a in ("c:\enxlogin\*") do @echo %%~na
echo.
echo Enter the Account you want to delete:
set /p deletingAcc="Account Name:"
if exist %deletingAcc%.txt goto delaccountnow
cls

echo Account not found
pause
goto DelAccount
echo            Cmd Delete Account
echo ======================================
echo.
:delaccountnow
del %deletingAcc%.txt
cls
echo            Cmd Delete Account
echo ======================================
echo.
echo Successfully Deleted Account
pause
goto home
:logdone
if %RegisterVal%==1 goto Register
if %DeleteAcc%==1 goto DelAccount
set Register=0
set actPass=NUL
set logPass=NUL
cls
echo              Cmd Login
echo ======================================
echo.
echo Successfully logged in!
echo.
pause
color 0f
cd "%userprofile%\Desktop"
cls
exit

这是我的批量密码脚本,它在启动cmd或批处理文件时运行,但是当用户按下ctrl-c或ctrl-break时,它会绕过登录脚本

这里发生了什么我运行cmd它启动所有工作,但当我按CTRL-C它退出并返回到正常CMD所以你可以搞乱cmd这是为了保护人们免于搞乱我的cmd在一个很酷的时尚

2 个答案:

答案 0 :(得分:3)

Ctrl-C无法取消下面的批处理文件,如果通过Ctrl-Break取消,则cmd.exe窗口关闭,因此用户永远无法访问正常的cmd.exe命令行会话< em>通过批处理文件。

@echo off
setlocal

if "%~1" equ "NonCancelable" goto NonCancelable
start "" /B cmd /C "%~F0" NonCancelable
exit

:NonCancelable
echo You can NOT cancel me!
echo/
set "var="
set /P "var=Enter password (enter Exit to end): "
if /I "%var%" neq "exit" goto :NonCancelable
echo Terminating non cancelable...
pause
exit

答案 1 :(得分:-1)

我遇到了同样的问题。

当通过ctrl + C终止批处理脚本时,cmd会话从该浴脚本的%CD%目录开始。我通过在另一个批处理脚本中分配一个批处理脚本来解决此问题,如下所示:

::launcher
@ECHO off
CD "directory of the batch script"
batchscript.cmd
EXIT

batchscript.cmd被ctrl + C终止时,它会返回到启动器,该启动器由于EXIT语句而立即关闭

(以管理员身份运行时需要CD语句。这是因为批处理脚本的CD变量将等于C:\ Windows \ System32。但是,如果批处理脚本的目录是CD语句,则可以省略包含在PATH变量中)