LuckyCla
LuckyCla

Reputation: 3

(batch) I wrote an IF statement for a set /p variable and the if statement completely disregards the variable and just goes to else

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
)

Upvotes: 0

Views: 369

Answers (1)

user7818749
user7818749

Reputation:

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

Upvotes: 1

Related Questions