编译批处理文件后,它停止工作

时间:2022-10-07 19:41:23

I'm writing a small folder locking software. Recently a masking function was integrated, so that the password input is masked. When in a bat file the program works perfectly, however after compiling the program stops working. The problem ,I think, lies in the "masking" code, as it starts an endless loop and masks every input, even the "Enter" stroke, thus preventing the program from further executing. I even tried iexpress, but it also gives an Error, namely:

我正在写一个小文件夹锁定软件。最近集成了屏蔽功能,因此屏蔽了密码输入。在bat文件中,程序运行正常,但编译后程序停止工作。我认为,问题在于“屏蔽”代码,因为它启动无限循环并屏蔽每个输入,甚至是“输入”笔划,从而阻止程序进一步执行。我甚至尝试过iexpress,但它也给出了一个错误,即:

Error creating process Command.com/c C:\Users...\AppData\Local\Temp\IXP000.TMP\Folder~1.BAT

创建进程时出错Command.com/c C:\ Users ... \ AppData \ Local \ Temp \ IXP000.TMP \ Folder~1.BAT

Can someone please double check my code and tell me what is wrong, as I am still learning and could not figure out how to fix it. Thanks in advance.

有人可以请仔细检查我的代码并告诉我有什么问题,因为我还在学习,无法弄清楚如何修复它。提前致谢。

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
mode con cols=80 lines=25
color 5F
title Folder Locker by KBKOZLEV
:SETPASS
set "tipp="
set "password="
if exist "password.txt" (
    set /p password=<password.txt
    attrib +h +s "password.txt"
)
if exist "tipp.txt" (
    set /p tipp=<tipp.txt
    attrib +h +s "tipp.txt"
)

:START
if exist "Locked" goto :OPEN
if exist "Unlocked" goto :LOCK
if not exist "Unlocked" goto :MDLOCKER

:LOCK
ren "Unlocked" "Locked"
attrib +h +s "Locked"
echo(
echo Folder locked.
CHOICE /C X /T 1 /D X > nul
goto :END
exit

:MDLOCKER
md "Unlocked"
echo>password.txt 1234
echo>tipp.txt 1234
attrib +h +s "password.txt"
attrib +h +s "tipp.txt"
cls
echo(
echo Private folder created successfully.
CHOICE /C X /T 1 /D X > nul
goto :END

:OPEN
color 2F
cls
echo ********************************************************************************
echo                          Folder Locker by KBKOZLEV v.01                       
echo. 
echo ********************************************************************************
echo ---- Enter password to unlock folder, or enter "new" to set a new password. ----
echo --------------------------------------------------------------------------------
echo.
echo Password tipp: %tipp%
echo(
set "pass="
rem set /p "pass=Password: "
Set /P "=Password:" < Nul
Call :PasswordInput pass

if /i "%pass%"=="new" goto :NEWPASS
if "%pass%"=="%password%" (
    attrib -h -s "Locked"
    ren "Locked" "Unlocked"
    echo(
    echo Folder unlocked successfully.
    goto :END
)
goto :FAIL

:FAIL
color 4F  
cls
echo(
echo Invalid password, please try again.
CHOICE /C X /T 1 /D X > nul
cls
goto :OPEN

:NEWPASS
color 8F
cls
echo(
set "oldpass="
rem set /p "oldpass=Old password: "
Set /P "=Old Password:" < Nul
Call :PasswordInput oldpass

if not "%oldpass%"=="%password%" goto :FAIL

:ENTERNEW
color 8F
cls
echo(
set "newpass=""
rem set /p "newpass=New password: "
Set /P "=New Password:" < Nul
Call :PasswordInput newpass

set newpass=%newpass:"=%
if "%newpass%"=="" (
    echo(
    echo Invalid new password, please enter new password again.
    CHOICE /C X /T 1 /D X > nul
    goto :ENTERNEW
)
if exist "password.txt" attrib -h -s "password.txt"
echo>password.txt %newpass%
echo(
set "passtipp=""
set /p "passtipp=New tipp: "
set passtipp=%passtipp:"=% 
if exist "tipp.txt" attrib -h -s "tipp.txt"
if not "%passtipp%"=="" (
    echo>tipp.txt %passtipp%
) else (
    del "tipp.txt" 
)
goto :SETPASS 

:END
color
EndLocal
Goto :Eof

:PasswordInput
::Author: Carlos Montiers Aguilera
::Last updated: 20150401. Created: 20150401. 
::Set in variable Line a input password
::
::Update 20150503: http://*.com/users/3439404/josefz?tab=profile
::Changes made in next lines:
::    SetLocal EnableDelayedExpansion
::    If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
::Usage:
::    Call :PasswordInput variableName
::where variableName is a name of output variable (by reference call)
:: 
SetLocal EnableDelayedExpansion
For /F skip^=1^ delims^=^ eol^= %%# in (
'"Echo(|Replace.exe "%~f0" . /U /W"') Do Set "CR=%%#"
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set "BS=%%#"
Set "Line="
:_PasswordInput_Kbd
Set "CHR=" & For /F skip^=1^ delims^=^ eol^= %%# in (
    'Replace.exe "%~f0" . /U /W') Do Set "CHR=%%#"
If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
    If !CHR!==!BS! (If Defined Line (Set /P "=!BS! !BS!" <Nul
        Set "Line=!Line:~0,-1!"
    )
) Else (Set /P "=*" <Nul
If !CHR!==! (Set "Line=!Line!^!"
    ) Else Set "Line=!Line!!CHR!"
)
Goto :_PasswordInput_Kbd

1 个解决方案

#1


You are executing the 16 bit command.com (only in Win 32) not the 32 or 64 bit cmd.exe. It doesn't suport brackets, long filenames, or set /p.

您正在执行16位command.com(仅在Win 32中)而不是32位或64位cmd.exe。它不支持括号,长文件名或set / p。

It also doesn't support long file names.

它也不支持长文件名。

#1


You are executing the 16 bit command.com (only in Win 32) not the 32 or 64 bit cmd.exe. It doesn't suport brackets, long filenames, or set /p.

您正在执行16位command.com(仅在Win 32中)而不是32位或64位cmd.exe。它不支持括号,长文件名或set / p。

It also doesn't support long file names.

它也不支持长文件名。