I'm working on a little script that should be simple but is really problematic. (I started learning command prompt and batch scripts a few days ago x.x ).
I need it to, when executed, change system year to 2010, and when executed again return to correct year. After a research I came up with this:
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
SETX DAY "%Date:~0,2%" /M
SETX MONTH "%Date:~3,2%" /M
SETX YEAR "%DATE:~-4%" /M
IF NOT "%year%"=="2010" (
SETX CPS_YEAR "%year%" /M
date %day%-%month%-2010
) ELSE (
date %day%-%month%-%cps_year%
)
The first part is a script I found (https://sites.google.com/site/eneerge/scripts/batchgotadmin) that asks administrator privileges to handle system variables, the problem is in my logic.
It kind of works, but after changing the year once, it need to be executed twice to change back. And twice again to change again.
Any leads on what could be causing this?
Many Thanks!