@ECHO OFF
cd /d %windir%
if exist "%userprofile%\desktop\winrpt.pdf" (
cd "%userprofile%\desktop\"
ren winrpt.pdf winrpt.log
) >nul
ECHO.  >>"%userprofile%\desktop\winrpt.log"
ECHO ***************************************************** >>"%userprofile%\desktop\winrpt.log"
ECHO    %date% %time% 執行啟用程式(v2.0) >>"%userprofile%\desktop\winrpt.log"
ECHO ***************************************************** >>"%userprofile%\desktop\winrpt.log"
ECHO.
ECHO   執行本程式前，請確認：
ECHO   您已在本程式上按右鍵，選「以系統管理員身份執行」，如否
ECHO   請關閉本程式，重新執行。
ECHO.
ECHO   Please make sure that you've right-click on this program and select
ECHO    "Run as administrator", if you are not, please exit and run again.
ECHO.
pause
ECHO ----------------------------------------------------------------
ECHO                       您正在啟用  Windows V1.5
ECHO                 (You are activating MS Windows)
ECHO ----------------------------------------------------------------
ECHO   步驟1：檢查是否已連上校園網路
ECHO   Step1. Check the Internet
ECHO.
ipconfig >"%userprofile%\desktop\ip.log"
find /C /I "140.119" "%userprofile%\desktop\ip.log" >nul
if %ERRORLEVEL% EQU 0 (
DEL /q "%userprofile%\desktop\ip.log"
goto act
) else (
DEL /q "%userprofile%\desktop\ip.log"
ECHO 　                    您可能尚未連上網校園網路
ECHO 　           ┌－－－－－－－－－－－－－－－－－－┐
ECHO 　           │如在在校外，請關閉此程式，連上VPN後 │
ECHO 　           │再執行一次，否則將啟用失敗。　　　　│
ECHO 　           └－－－－－－－－－－－－－－－－－－┘
ECHO.                    
ECHO   Please make sure that your computer must connect to the campus internet,
ECHO   or through VPN. Otherwise, failed to activate.
ECHO.
ECHO 是否關閉此程式?
ECHO Exit?
CHOICE /C yn /M "Y)是Yes  N)否，我已連上校內網路，繼續啟用 No, I'll keep trying."
if ERRORLEVEL 2 goto act
if ERRORLEVEL 1 goto cnct
)

:act
ECHO   步驟2：指定KMS伺服器：出現對話框時，請按下「確定」。
ECHO   Step2. Set KMS host, please click 'OK'.
slmgr -skms cckms.nccu.edu.tw:1688
ECHO.
ECHO   步驟3：正在啟用，請稍候。
ECHO   Step3. Activating products, please wait...
slmgr -ato
ipconfig >>"%userprofile%\desktop\winrpt.log"
cd "%userprofile%\desktop\"
ren winrpt.log winrpt.pdf
ECHO.
ECHO ----------------------------------------------------------------
ECHO.
ECHO   啟用動作完成，如果過程中出現錯誤訊息，請查看常見問題:
ECHO   "https://support.video.nccu.edu.tw/km/1091/faq"
ECHO.
ECHO   或記下該代碼、附作業系統版本及桌面上winrpt.pdf，
ECHO   至http://cis.nccu.edu.tw/67599提問
ECHO   (winrpt.pdf無法開啟為正常現象)
ECHO.
ECHO   Activation processes complete, if error code shows up during the processes, 
ECHO   please check the error code solution in the following page:
ECHO   "https://support.video.nccu.edu.tw/p/casfaq-en"
ECHO.
ECHO   Or send the error code and the file winrpt.pdf on desktop 
ECHO   to software@nccu.edu.tw
ECHO   Please notice that office14rpt.pdf is unreadable which is normal.
ECHO.
pause
exit

:cnct
ECHO ===IP issue=== >>"%userprofile%\desktop\winrpt.log"
netstat -n -p tcp >>"%userprofile%\desktop\winrpt.log"
cd "%userprofile%\desktop\"
ren winrpt.log winrpt.pdf
exit