Solved echo still appears if not EQU to Y and other questions

April 2, 2016 at 18:04:39
Specs: Windows 8.1, 32 GB
Hello, I'm really new to Batch scripting, I've been creating a batch script that turns the user DEP ON or OFF.

My problem right now is that my if statement is not working the way I wish it would.

Anyways what it does/doesn't is simple:

1 - Ask the users if they wish to turn the DEP ON or OFF.
2- Ask the users if they wish to restart the computer so the changes can be applied.
3- if They say Y to restart it will restart their pc in 30 seconds.
4- If answering Y to the restart question, it ask if they wish to abort the shutdown -r command.
5- If answering N cls the window and tell them that they still need to restart for the changes to apply.

My problem right now is that number 5 when I answer No for if I would like to restart the computer now the second message that asks the user if they wish to abort the reboot of their computer still show up.
Not sure why.

Here is my code:


echo ***** YOU NEED TO RESTART YOUR COMPUTER SO THE CHANGES CAN BE APPLIED! *****
                      echo.
                      echo.
                      echo ***MAKE SURE TO SAVE ALL YOUR DOCUMENTS BEFORE RESTARTING YOUR COMPUTER OR YOU WILL LOOSE EVERYTHING!!***
                      echo.
                      set /p RESTART= WOULD YOU LIKE TO RESTART YOUR COMPUTER NOW?(Y/N):
                      echo.







                            if /I %RESTART%==Y (
                                    echo.
                                    echo.
                                    echo YOUR COMPUTER WILL BE REBOOTED IN 30 SECONDS!!!

                                    shutdown -r -f -t 30

                                    goto Ryes

                                    )

                                        :Ryes
                                        echo.
                                        set /p ABORT= WOULD YOU LIKE TO ABORT THE REBOOT?(Y):
                                        echo.





                                            if /I %ABORT%==Y (

                                            goto Abor
                                            echo.
                                                  echo YOU ABORTED THE REBOOT OF YOUR COMPUTER.
                                            echo.
                                            ) else (

                                            echo.
                                            echo.
                                            echo YOUR COMPUTER WILL REBOOT SOON!
                                            echo.

                                            )



                                                    :Abor

                                                    shutdown /a

pause


I would appreciate any help and suggestions to change my code for better. Like I stated above I'm really new to batch scripting.

Well thank you for your help and time, have a nice one!


See More: echo still appears if not EQU to Y and other questions

Report •


✔ Best Answer
April 4, 2016 at 23:57:29
If your .bat to .exe compiler doesn't have an option to choose between 32-bit and 64-bit, F2KO Software has a pretty decent compiler
http://www.f2ko.de/en/b2e.php

Been using this for quite a while, and also has an option to add an administrator manifest as you said you needed earlier.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)



#1
April 3, 2016 at 12:42:00
You have the cancel shutdown command outside the IF statements, which means it will be executed regardless of what the user inputs.

In your script, the user would only have the chance to cancel it once, you should add a loop that loops the question until the computer reboots.

Made some slight improvements:

echo ***** YOU NEED TO RESTART YOUR COMPUTER SO THE CHANGES CAN BE APPLIED! *****
echo.
echo.
echo ***MAKE SURE TO SAVE ALL YOUR DOCUMENTS BEFORE RESTARTING YOUR COMPUTER OR YOU WILL LOOSE EVERYTHING!!***
echo.
set /p RESTART="WOULD YOU LIKE TO REBOOT YOUR COMPUTER NOW? (Y/N)>> "
echo.
if /I "%RESTART%"=="Y" (
	echo.
	echo.
	echo YOUR COMPUTER WILL BE REBOOTED IN 30 SECONDS!!!
	shutdown -r -f -t 30
	goto Ryes
) else (
	goto Relse
)
:Ryes
echo.
set /p ABORT="ENTER 'Y' TO ABORT THE REBOOT: "
echo.
if /I "%ABORT%"=="Y" (
	shutdown /a
	echo.
	echo YOU ABORTED THE REBOOT OF YOUR COMPUTER.
	echo.
        goto Relse
) else (
	goto Ryes
)
:Relse
pause

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Report •

#2
April 3, 2016 at 14:00:18
LOL.
Finally some help. I appreciate.

It worked good now but I would like to know if you could explain why you used ""
I thought that was comments in batch file but still works normal.
am I wrong?

Thank you!


Report •

#3
April 3, 2016 at 14:53:46
The quotes are to prevent the script from crashing if no input is entered.

Without the quotes, here's what would happen:

if /i %ABORT%==Y goto :Ryes

would become
if /i ==Y goto :Ryes

This is would crash the program as it creates a syntax error. When using quotes, it would be like this:
if /i ""=="Y" goto :Ryes

Since the command processor now has something to compare, it does no longer crash due to a syntax error.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Report •

Related Solutions

#4
April 3, 2016 at 15:30:20
Got it, thank you very much!

Can you help me with one more thing?

So I converted my .bat to .exe

but now it can't find the bcdedit.exe file.

here it how it looks:


   echo  1.Opt-In (Enable DEP)
              echo  2.Opt-Out (Disable DEP)
echo.
        set /p CHANGE= WHAT WOULD YOU LIKE TO DO?(1/2):

        echo.


          :1

          bcdedit.exe /set {current} nx OptIn
          echo.
            goto reb


              :2

              bcdedit.exe /set {current} nx AlwaysOff
              echo.
                goto reb

                      :reb

echo ***** YOU NEED TO RESTART YOUR COMPUTER SO THE CHANGES CAN BE APPLIED! *****
echo.
echo.
echo ***MAKE SURE TO SAVE ALL YOUR DOCUMENTS BEFORE RESTARTING YOUR COMPUTER OR YOU WILL LOOSE EVERYTHING!!***
echo.
set /p RESTART="WOULD YOU LIKE TO REBOOT YOUR COMPUTER NOW? (Y/N)>: "
echo.



					if /I "%RESTART%"=="Y" (
						echo.
						echo.
						echo YOUR COMPUTER WILL BE REBOOTED IN 30 SECONDS!!!
						shutdown -r -f -t 30
						goto Ryes

							) else (
								goto Relse
							)
								:Ryes
								echo.
								set /p ABORT="ENTER 'Y' TO ABORT THE REBOOT: "
								echo.




									if /I "%ABORT%"=="Y" (
										shutdown /a
										echo.
										echo YOU ABORTED THE REBOOT OF YOUR COMPUTER.
										echo.
									        goto Relse
									) else (
										goto Ryes
									)
:Relse
pause


with .bat it works fine, it finds the bcdedit.exe file.
but when I convert to .EXE it says this:


'bcdedit.exe' is not recognized as an internal or external command,
operable program or batch file.

Now I saw some stuff online saying that is because I have to put the PATH of the file in this case the bcdedit.exe is located in C:\Windows\System32
but I have no idea how to change the batch file to find the bcdedit.exe inside the System32 folder.

Can you help me out and maybe explain to me why you do like that?

thank you very much!!!


Report •

#5
April 4, 2016 at 07:36:25
What error message do you get? Does it not recognise bcdedit as a command?

Also, why would you want to convert it into an exe anyways?

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Report •

#6
April 4, 2016 at 07:58:43
I get this:

'bcdedit.exe' is not recognized as an internal or external command,
operable program or batch file.

I want as a .EXE because I need the admin manifestation option.


Report •

#7
April 4, 2016 at 08:13:11
Only thing I can think of is replacing the comand with the full path to the executable, aka
"%SYSTEMROOT%\System32\bcdedit.exe"

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Report •

#8
April 4, 2016 at 08:27:33
Still with that I get this:


'"C:\WINDOWS\System32\bcdedit.exe"' is not recognized as an internal or external
 command,
operable program or batch file.

any other way to add the path of the bcdedit.exe?

thank you :)


Report •

#9
April 4, 2016 at 10:48:26
I'll give you a hint, because I'm psychic.

Your OS is 64-bit. Your converted batch file is 32-bit.

How To Ask Questions The Smart Way


Report •

#10
April 4, 2016 at 13:46:12
How do I convert to 64 bits?
Weird the .exe file still runs on my pc, my pc is 64 bits it shouldn't run right?

Report •

#11
April 4, 2016 at 14:34:12
How do I convert to 64 bits?
You get a program that makes a 64-bit executable.

Weird the .exe file still runs on my pc, my pc is 64 bits it shouldn't run right?
32-bit Windows can run 16-bit and 32-bit applications.
64-bit Windows can run 32-bit and 64-bit applications.

How To Ask Questions The Smart Way


Report •

#12
April 4, 2016 at 23:57:29
✔ Best Answer
If your .bat to .exe compiler doesn't have an option to choose between 32-bit and 64-bit, F2KO Software has a pretty decent compiler
http://www.f2ko.de/en/b2e.php

Been using this for quite a while, and also has an option to add an administrator manifest as you said you needed earlier.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Report •


Ask Question