I dont know why my batch if and goto isnt working - if-statement

I dont know why my batch if and goto isnt working
it works until the user has to pick a choice to run. The whole thing just shutsdown
Here is my script:
#Echo off
:Password
set input=
set b=
set c=
set /p input=Password:
if %input%==******** goto yes
if not %input%==******** goto no
cls
:yes
cls
echo Access Accepted! Welcome Tucker!
echo.
set /p op=Enter Your Full-Name For Access:
if %op%== TuckerGarySiegel goto home
cls
:no
echo Wrong Password. Access Denied. No Entry.
goto password
cls
:home
color 1f
This is what I think is the problem area
Echo Welcome Tucker!
echo 1) My Batch Files
echo 2) Google Chrome
set /p input=Type Your Selection:
if %c%== 1 goto batch
if not %c%== 1 goto home
pause
cls
:batch
echo Choose File:
echo 1) Password Script
set /p b=Make Selection:
if %b%== 1 goto passscript
pause
cls
:passscript
i still need to make the rest
please help

set /p input=Type Your Selection:
if %c%== 1 goto batch
if not %c%== 1 goto home
You're setting the variable input but then checking the variable c. Try this instead, which will allow it to work:
set /p input=Type Your Selection:
if %input%== 1 goto batch
if not %input%== 1 goto home
P.S. you don't need to check an if and an if not. Doing this would be just fine:
set /p input=Type Your Selection:
if %input%== 1 goto batch
goto home

Related

Find and remove remote hidden file

I'm trying to create a small script that looks for a specific file in an hidden folder and remove it using IF ELSE, but it doesn't seem to work. It works when I try to find and delete a local file, but not when I try a remote hidden file.
This is my code:
#echo off
set /p destination="Enter destination PC name: "
#echo off
set /p username="username: "
echo.
echo [33m'Removing 'notes.ini' file[0m
timeout /T 2 /NOBREAK > nul
echo.
if exist "\\%destination%\C$\Users\%username%\AppData\Local\Lotus\Data\notes.ini" (
del /A /Q /F "\\%destination%\C$\Users\%username%\AppData\Local\Lotus\Data\notes.ini"
echo [92m'Notes.ini' cleared.[0m
) else (
echo [33m'Notes.ini' doesn't exist.[0m
)
echo.
timeout /T 2 /NOBREAK > nul
echo [92mScript clompleted[0m
I tried with a local file, and then the scripts works, but not with a remote hidden file. I always get the "else" statement as return with hidden files

URL with operators (=, -) not working within if-statement

I'm having an issue with an URL in an if-statement using batch.
#ECHO OFF
SET /P input="Insert Link "
if %input%==l (echo true) else (echo false)
cmd /k
I want to determine if the user input is a link or a single character (in this case l). I get that the operators within the URL might cause the problem. But shouldn't the if-statement just check if %input% is l and everything else would trigger the else? Using SET %input%=l leads to the true case being triggered.
Any ideas on how to make this work in a simple way? Am I missing something regarding syntax?
Putting %input% and l within the if-statement in quotes solved the problem.
#ECHO OFF
SET /P input="Insert Link "
if "%input%"=="l" (echo true) else echo false
cmd /k
The way the Command Line works, %ThisIsAVariable% will be replaced with whatever ThisIsAVariable contains and then be interpreted as such. Hence, running your example prompts the following error:
=6zswl5YrvVw==l was unexpected at this time.
The simplest way to solve this is to wrap your %input% with ""
e.g.
#ECHO OFF
SET input=https://www.youtube.com/watch?v=6zswl5YrvVw
if "%input%"==l (echo true) else (echo false)
cmd /k
That would prompt false

using TCL command line, is there a way to stop showing characters?

I'm building a tool were a command with a password needs to be entered.
I want when I enter this command with the password, the command line replaces each character with "*" or " ", so the command and the password will not be observable !
is there such a command that tells the TCL interpreter "from this point, show each character entered as *", and then switch back to regular mode ?
any other suggestion will be valuable too.
In your case, you shall take "full control" over your terminal and disable its default echoing behavior (In UNIX the likes the terminal should be entered into the so-called raw mode)
Then, you can read the characters one-by-one (till max password size or till Enter is pressed) and echo '*' per each pressed character.
You got working code examples both on UNIX and Windows how doing so here
You may want reading also this link echo-free password entry TCL wiki
proc enableRaw {{channel stdin}} {
exec /bin/stty raw -echo <#$channel
}
proc disableRaw {{channel stdin}} {
exec /bin/stty -raw echo <#$channel
}
enableRaw
set c [read stdin 1]
puts -nonewline $c
disableRaw
package require twapi
proc enableRaw {{channel stdin}} {
set console_handle [twapi::GetStdHandle -10]
set oldmode [twapi::GetConsoleMode $console_handle]
set newmode [expr {$oldmode & ~6}] ;# Turn off the echo and line-editing bits
twapi::SetConsoleMode $console_handle $newmode
}
proc disableRaw {{channel stdin}} {
set console_handle [twapi::GetStdHandle -10]
set oldmode [twapi::GetConsoleMode $console_handle]
set newmode [expr {$oldmode | 6}] ;# Turn on the echo and line-editing bits
twapi::SetConsoleMode $console_handle $newmode
}
enableRaw
set c [read stdin 1]
puts -nonewline $c
disableRaw
(Assuming Linux.) By far the easiest way to handle passwords in a terminal is to turn off echoing of input but leave the terminal otherwise in cooked mode. It won't show a * for each entered character, but it does mean that you don't have to handle things like backspace (when a user realises they typed the last couple of characters wrong before hitting Return), etc.
exec /bin/stty -echo <#stdin
set password [gets stdin]
puts ""
exec /bin/stty echo <#stdin
If you've got Tcl 8.6, you can easily make this more robust with this procedure:
proc getPassword {{prompt "Password: "}} {
exec /bin/stty -echo <#stdin
try {
puts -nonewline $prompt
flush stdout
return [gets stdin]
} finally {
puts ""
flush stdout
exec /bin/stty echo <#stdin
}
}
(It's possible to use catch and some scripting to emulate try…finally but it's really annoying.)
If you have a GUI and prefer that, you make a password entry box by setting the -show option to something non-empty (e.g., * to show an asterisk).

Batch - User Input to Command Prompt (IF statement issue)

I am currently creating a segment of a larger batch file that needs to let the user interact with the command prompt, but I seem to be having issues with the IF Statements.
The following code is what I've been trying:
:ONE2
cls
echo Free Roam is used like command prompt, but with additional commands.
echo Type FRHELP for a list of additional commands.
:COMMANDLOOP
echo.
set /P TEMPCMD=%CD% :
IF %TEMPCMD% == QUIT (
GOTO END2
) else if %TEMPCMD% == FRHELP (
GOTO COMMANDSLIST
) else (
%TEMPCMD%
GOTO COMMANDLOOP
)
:COMMANDSLIST
echo.
echo FRHELP = Display Free Roam Commands
echo QUIT = Leave your current Free Roam Session
GOTO COMMANDLOOP
What happens is, I can make multi-part commands (EG: cd ..) without the IF statements. But with the IF statements, it will only allow me to make single part commands (EG: dir).
If I have the IF statements as listed above, it will give me the "'..' was unexpected" error and exit.
Is there any way to pass my TEMPCMD variable to the command prompt with these IF statements and not get this error?
try this, it works for me without any error:
#echo off &setlocal
:COMMANDLOOP
echo.
set "TEMPCMD=%CD%"
set /P "TEMPCMD=%CD% :"
IF "%TEMPCMD%"=="QUIT" (GOTO END2
) else (
if "%TEMPCMD%"=="FRHELP" (
GOTO COMMANDSLIST
) else (
GOTO COMMANDLOOP
)
)
pause
:COMMANDSLIST
echo.
echo FRHELP = Display Free Roam Commands
echo QUIT = Leave your current Free Roam Session
GOTO COMMANDLOOP

what is wrong with this conditional (if-else) execution in batch script?

I am testing some small scripts that I have. This particular one is driving me crazy. In my mind it should work, but it is not doing what I thought it would/should.
#echo off
echo testing the issue
echo.
ECHO Checking the log file for errors...
echo %errorlevel%
FINDSTR /C:"open failed" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else (GOTO TSTErrChecking1)
:TSTErrChecking1
FINDSTR /C:"does not exist" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else (GOTO TSTErrChecking2)
:TSTErrChecking2
FINDSTR /C:"Logon failed" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else ( GOTO TSTErrChecking3)
:TSTErrChecking3
FINDSTR /C:"Failure" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else ( GOTO TSTErrChecking4)
:TSTErrChecking4
FINDSTR /C:"RC (return code) = 0" C:\automatic_deployment\test1.txt
echo %errorlevel%
IF %ERRORLEVEL% == 0 (
ECHO Deployment was successful.
pause
GOTO quit) ELSE (
ECHO Deployment failed.
pause
GOTO quit)
:quit
exit
As you can see I am using "FINDSTR" to find certain words/strings from a small test1.txt file and act accordingly. I want it to say "deployment failed" and quit asap if it sees any "fail"/ "does not exist"/"open failed". If it cannot find anyone of those above and finds the "RC (return code) = 0" I want it to say it was "successful".
So, i put all those test words and strings in my test1.txt file and tested the batch script, but it keeps skipping (i think) all those fail hints/words and keeps saying it was successful. Plz, help. Thanks in advance.
it could be that you already have an %ERRORLEVEL% variable defined in your environment
Read
Raymond Chen's ERRORLEVEL is not %ERRORLEVEL% http://blogs.msdn.com/b/oldnewthing/archive/2008/09/26/8965755.aspx
and then try
FINDSTR /C:"RC (return code) = 0" test.txt
IF ERRORLEVEL 1 ECHO Deployment failed.
I just didn't have the matching strings to search for. I didn't know that FINDSTR looked for EXACTLY the same case letters when searching and comparing. That was the problem.