0

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:

Error creating process 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://stackoverflow.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
Kaloian Kozlev
  • 43
  • 1
  • 11
  • What are you using to compile? – paxdiablo May 04 '15 at 06:14
  • Bat To Exe Converter v.2.1.5 – Kaloian Kozlev May 04 '15 at 06:19
  • I hate batch-to-exe converters with a passion, so I'll try to be as nice as possible: there's no good reason to ever use one. Not one. If you're honestly trying to encrypt your code, you need to completely overhaul your system so that you aren't using a scripting language, which _by definition_ is meant to be run in plain text. Also, that masking code is hideous, use [this](http://www.dostips.com/forum/viewtopic.php?f=3&t=227&p=33538#p33538) instead. – SomethingDark May 04 '15 at 07:25
  • check also this - http://stackoverflow.com/questions/28174386/how-can-a-bat-file-be-converted-to-exe-without-third-party-tools – npocmaka May 04 '15 at 08:17
  • Hey, it's not so much about the encriptuon. i want to send the programm to my friends, but I want to add and icon, and I also want to prevent them from.being able to edit the code. If there is another way I can do it, I do not necessarirly need it to be an exe file. – Kaloian Kozlev May 04 '15 at 08:18

1 Answers1

0

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.

It also doesn't support long file names.

Trigger
  • 135
  • 3
  • thank you for the answer. Could you suggest a way to fix it, or to rewrite it, in order for the program to be able to be converted? – Kaloian Kozlev May 04 '15 at 13:22
  • Your problem is with your bat2exe program not your batch file. Either it is totally stupid or you have configured it wrong. – Trigger May 05 '15 at 01:38