Skip to content

Instantly share code, notes, and snippets.

@dibyasonu
Last active December 9, 2018 16:50
Show Gist options
  • Save dibyasonu/938bbef18e44c9b3f8020f63c36b9326 to your computer and use it in GitHub Desktop.
Save dibyasonu/938bbef18e44c9b3f8020f63c36b9326 to your computer and use it in GitHub Desktop.
A small batch script to run MATLAB 2017 after license has expired.

Steps

  • Copy the below code and save it with any name and extension as .bat .
  • When you need to run MATLAB execute the file you have created.
  • After the activation is complete, the application can run with original time. So the script pauses for 60 sec after starting the application and then restores the actual time. This allows you to use internet while using MATLAB. But depending on different system, the time to start MATLAB may vary.
    So you can change the code accordingly, by changing the line 47 if required timeout /t [time in sec].

Optional

  • Keep the file in your matlab project folder and add the folder to the path.
  • You can create a shortcut for better use.
  • The time sync works only if internet connection is there, so accordingly sync your system time if required.
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>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"
:--------------------------------------
REM we got the present date
(powershell get-date -format "{MM-dd-yyyy}")>>x.txt
set /p curdate=<x.txt
del x.txt
REM set the old date to fool matlab
echo changing system date...
date 09/12/2017
echo system date changed succesfully to 12-sep-2017.
REM invoke matlab
echo. && echo starting matlab...
start /b matlab
timeout /t 60
REM change the date to original
echo. && echo restoring system date...
date %curdate%
date /t
echo system date restored succesfully. && echo.
REM sync with internet time servers
w32tm /resync
echo. && echo if sync was not succesful, you can manually sync with internet time
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment