Batch Script to Change System’s Date

Sometimes, you need to run an obsolete app that is restricted by time. Backdating manually is not practical since you open the app quite often. It will harm other apps as well, such as Office 365. You have to revert the date again to the true time after that. It is quite disturbing and takes your valuable time. You need a batch script to do that all. What you want to do is just double clicking an icon like you open that app.

Okay, here is the simple algorithm:

  • earn administration permission, since changing the system’s date needs that
  • get the current true date
  • backdate the system’s date
  • open the app
  • wait for several seconds until the app finished checking the date
  • revert back the date
To do that, copy paste the script below into Notepad and save it as changedate.bat or whatever:

 

@echo off
:: EARN ADMINISTRATION PERMISSION
:-------------------------------------
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"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B
:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:: GET CURRENT DATE
:-------------------------------------
set BEFOREDATE=%date:~%
:: BACKDATE THE DATE
:-------------------------------------
echo 11-11-14 | date
:: RUN THE APP
:-------------------------------------
start /d "C:\Path to App" theapp.exe
:: WAIT FOR 7 SECONDS, BREAK WAIT BY CTRL+C
:-------------------------------------------
timeout /t 7 /nobreak
:: REVERT THE DATE
:-------------------------------------
echo %BEFOREDATE% | date


		

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s