Batch File not working.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
wjclancy13
Posts: 2
Joined: 01 Dec 2017 21:23

Batch File not working.

#1 Post by wjclancy13 » 02 Dec 2017 08:51

Hey guys!
I've been playing around with some batch files and trying to create various (useless and pointless) programs to do random stuff with. My latest one has been malfunctioning and I'm not sure why. It's essentially a program which sets a password. If the password is entered correctly it begins a program which creates infinite folders that can only be stopped by closing the program. The code is as follows:

Code: Select all

@echo off
title Gate
set tries=1
set password=a215
echo.
echo Enter password to activate.
echo.

set p/ pass
if %pass%=%password% (
goto accepted
)
set tries /a tries=%tries -1
if %tries%===0
goto denied

:denied
echo Access Denied
start shutdown -s -t 35 -c Security Breach Averted
cls 

:accepted
echo This is your own fault. Do you accept? Press any key for yes, exit this program for no.
pause
echo So be it. 
goto start

:start
mkdir %random%
goto start
If anyone knows why this isn't working, could you let me know? Thanks! I'm not sure why its doing this, but whenever it opens it immediately shuts. Thanks again!
-wjclancy13
Last edited by aGerman on 02 Dec 2017 09:19, edited 1 time in total.
Reason: code tags added

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch File not working.

#2 Post by aGerman » 02 Dec 2017 09:15

Many syntax errors ...
wjclancy13 wrote:
02 Dec 2017 08:51
set p/ pass
Where is the equal sign that belongs to an assignment?
wjclancy13 wrote:
02 Dec 2017 08:51
if %pass%=%password% (
...
if %tries%===0
Neither = nor === is a comparison operator in batch. It's ==.
wjclancy13 wrote:
02 Dec 2017 08:51
set tries /a tries=%tries -1
goto denied
The second percent sign is missing but actually set /a "tries-=1" would have been the better syntax. Why is goto denied in the next line?

That's what I found in the first place. There might be more failures...

Steffen

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Batch File not working.

#3 Post by Squashman » 02 Dec 2017 09:56

A lot of your problems could be fixed by yourself if you learn to debug your batch file correctly.

First rule of debugging a batch file is run the batch file from the cmd prompt.

Second rule is don't use ECHO OFF. This will help you see the commands execute.

Third rule is read the help file for the command. You can open up a cmd prompt and type the command name followed by a forward slash and question mark. Most of your errors were basic syntax issues which tells me you did not read the help for any of the commands.

wjclancy13
Posts: 2
Joined: 01 Dec 2017 21:23

Re: Batch File not working.

#4 Post by wjclancy13 » 02 Dec 2017 14:03

Thanks! As you can see, I'm very new to this. I appreciate your help!

Post Reply