@echo off
:: BatchGotAdmin (Run as Admin code starts)
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"
:: BatchGotAdmin (Run as Admin code ends)

@Echo off
cd /d "%~dp0"
ECHO ..................................................
ECHO Copying Mysql Backup to C:\ Drive For CCTNS Taking Bakup of Offline Database
ECHO ..................................................

ECHO Creating local directory

ECHO Copying Mysql Backup into C drive

xcopy .\CCTNS-MySQLBackups  C:\CCTNS-MySQLBackups\   /e /i /h /Y

SCHTASKS /Create /SC DAILY /TN MYSQL /TR C:\CCTNS-MySQLBackups\mysqlbackup.bat /ST 17:00 /F
SCHTASKS /Create /SC DAILY /TN MYSQL2 /TR C:\CCTNS-MySQLBackups\mysqlbackup.bat /ST 10:00 /F
Echo Task Scheduler has been Configured for Taking Backup on daily basis.

copy .\CCTNS-MySQLBackups\zip\Mysql.bat "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" 
IF EXIST "C:\Program Files (x86)\7-Zip\Lang" GOTO END
.\"7z920.exe"
:END
REGEDIT.EXE /S .\default.reg
Echo "Homepage Updated"

Echo -Starting Automatic Backup before Updating Offline DB Please Wait-
C:\CCTNS-MySQLBackups\mysqlbackup.bat
Echo Back Up finished for CAS DB 3.0 Please close the window and press any key-
TIMEOUT /T 2 /NOBREAK

