0

I have never worked with batch before but it seemed pretty easy up until this. When I run the batch file, you are greeted with a prompt that says "Do you want to enable or disable dark mode? [E/D]?" No matter what response you send, it still runs DarkModeOff.bat. This file is made to run two other batch files that run the registries required to enable/disable dark mode in windows, for people who did not activate windows. Here's my code for reference:

@echo on
setlocal enableextensions
cd regestries
set /p /i choice=Do you want to enable or disable dark mode? [E/D]
if '%choice%' == 'E' (
    DarkModeOn.bat
) else (
    DarkModeOff.bat
)
LuckyCla
  • 3
  • 2
  • 1
    `/i` is not a valid switch for the `set` command – T3RR0R Aug 10 '20 at 13:32
  • 1
    `/i` is however a valid switch for `IF` to disregard case. the syntax for safe conditional testing of strings is: `If /i "%var%"=="Value" (command) Else (Other Command)` – T3RR0R Aug 10 '20 at 13:34
  • 1
    and of course, [choice](https://ss64.com/nt/choice.html) is much safer to use than `set /p` – Stephan Aug 10 '20 at 13:36
  • You should also confirm the Change Directory command, `cd regestries || Echo/Directory does not exist in %CD%` – T3RR0R Aug 10 '20 at 13:37
  • @T3RR0R That fixed it. I saw on some website that it said /i was a perimeter to disregard case, but I thought it went in the set command. Thank you for helping me. – LuckyCla Aug 10 '20 at 13:43
  • 1
    @LuckyCla I recommend to use the code provided by Gerhard. You could read my long answer on [How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?](https://stackoverflow.com/a/49834019/3074564) in case of being interested in the reasons for using `choice` instead of `set /P` wherever possible. – Mofi Aug 10 '20 at 17:29

1 Answers1

1

use choice instead. by default it is not case sensitive.

@echo off & setlocal enabledelayedexpansion
set "_1=On" & set "_2=Off"
echo cd regestries
choice /c ed /m "Do you want to enable or disable dark mode?"
call DarkMode!_%errorlevel%!.bat
Gerhard
  • 22,678
  • 7
  • 27
  • 43