I've been experiencing an issue, and I don't really know where is the problem or if I set a variable I shouldn't use. When I run this script with administrator rights it all goes well, but when I do not it simply should just show me the message at the bottom, but instead it goes to the variable of restart which is inside the if (true).
How can I fix it?
@echo off
goto check_Permissions
:check_Permissions
##Reddit: from here everything starts##
echo Permisos de administrador requeridos. Detectando permisos...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Exito: Permisos de administrador confirmados.
##Reddit: if it detects admin rights it goes well##
timeout 5
:choice
echo Some echo here
echo NOTA: Si presionas Ctrl+C en una pausa ejecutara el codigo siguiente, para cerrarlo usa ALT+F4 o con el raton.
echo Selecciona:
echo [A] Escribir IP estatica
echo [B] Seleccionar DHCP
echo [C] Insertar sufijo DNS
echo [D] Insertar nuevo nombre de equipo
echo [E] Meter equipo en dominio
echo [Y] Reiniciar
echo [Z] Salir
echo.
SET /P C=[A,B,C,D,E,Y,Z]?
for %%? in (A) do if /I "%C%"=="%%?" goto A
for %%? in (B) do if /I "%C%"=="%%?" goto B
for %%? in (C) do if /I "%C%"=="%%?" goto C
for %%? in (D) do if /I "%C%"=="%%?" goto D
for %%? in (E) do if /I "%C%"=="%%?" goto E
for %%? in (Y) do if /I "%C%"=="%%?" goto Y
for %%? in (Z) do if /I "%C%"=="%%?" goto Z
goto choice
##Reddit: a lot of code goes here, not relevant##
:Y
echo ¿Quieres reiniciar el equipo? (S/N)
##Reddit: The variable thats causing me problems##
set /P D=[S,N]?
for %%? in (S) do if /I "%D%"=="%%?" goto shutdown
for %%? in (N) do if /I "%D%"=="%%?" goto choice
:shutdown
shutdown -r -t 30
echo Reiniciando el equipo en 30 segundos
timeout 30 /NOBREAK
:Z
exit
:end
pause
) else (
echo Fracaso: Permisos insuficientes.
##Reddit: if it reaches here because insufficient permissions this happens, (see image below)##
echo EJECUTA ESTE SCRIPT COMO ADMINISTRADOR
)
pause >nul