@ECHO OFF
title ★ office2016 四合一绿色精简版 ★
mode con: cols=80 lines=22
ver | find "5.0." > NUL && set winos=xpos
ver | find "5.1." > NUL && set winos=xpos
ver | find "5.2." > NUL && set winos=xpos
ver | find "6.0." > NUL && set winos=win7os
ver | find "6.1." > NUL && set winos=win7os
ver | find "6.2." > NUL && set winos=win8os
ver | find "6.3." > NUL && set winos=win8os
ver | find "6.4." > NUL && set winos=win8os
ver | find "10." > NUL && set winos=win8os
IF /i %winos%==xpos (echo     Office2016 不支持该系统！& pause>nul & exit)
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (goto UAC) else ( goto Administrator )
:UAC
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /b
:Administrator
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
PUSHD %~dp0
SET PATH=%PATH%;%CD%;%CD%\OSPP
IF /i %PROCESSOR_ARCHITECTURE%==AMD64 (
    SET ARCH=X64
    SET SYSPath=%SystemRoot%\sysWOW64
    SET "MSharedPATH=%CommonProgramFiles(x86)%\Microsoft Shared"
) ELSE (
    SET ARCH=X86
    SET SYSPath=%SystemRoot%\system32
    SET "MSharedPATH=%CommonProgramFiles%\Microsoft Shared"
)
color 2f
cls
echo.
echo.
echo                      Office2016 pro plus vol 四合一绿色精简版
echo.
echo   ---------------------------- 2016.02.21 by xb21cn --------------------------
echo.
echo                      支持 win7 win8 win8.1 win10 x86/x64 系统
echo.
echo.
IF /i %winos%==win8os (
color 4F
echo.
echo.              　　　　　　★★★　重要提示！！！★★★
echo.
echo   　　　　　因激活机制原因，首次安装本绿色版会造成系统变为180天试用，
echo.
echo   　　　　　　　　　　　　　　　安装前请三思！！！
echo.
echo.
echo     　　　　　　按任意键继续安装，否则直接关闭本窗口退出安装！
pause>nul
color 2f
cls
)
echo  正在安装，请耐心等待…………
if NOT EXIST "%MSharedPATH%\VC\msdia100.dll" (START /wait ospp\vc2010.exe /q)
"%~dp0ospp\7za.exe" e -y "ospp\QuickToobar.7z" -o"%UserProfile%\AppData\Local\Microsoft\Office" >nul 2>nul
"%~dp0ospp\7za.exe" x -y "ospp\MShared.7z" -o"%MSharedPATH%" >nul 2>nul
"%~dp0ospp\7za.exe" x -y "ospp\ShellNew.7z" -o"%Windir%" >nul 2>nul
REGSVR32 /s "%MSharedPATH%\MSClientDataMgr\MSCDM.dll"
REGSVR32 /s "%MSharedPATH%\Office16\MSOXEV.dll"
REGSVR32 /s "%MSharedPATH%\Office16\msoshext.dll"
REGSVR32 /s "%MSharedPATH%\VBA\VBA7.1\VBE7.dll"
REGSVR32 /s "Office16\Addins\OTKLOADR.dll"
REGSVR32 /s "Office16\ACCWIZ.dll"
REGSVR32 /s "Office16\IEAWSDC.dll"
REGSVR32 /s "Office16\MSOEURO.dll"
REGSVR32 /s "Office16\MSOHEV.dll"
REGSVR32 /s "Office16\MSOHEVI.dll"
REGSVR32 /s "Office16\MSRTEDIT.dll"
REGSVR32 /s "Office16\REFEDIT.dll"
REGSVR32 /s "Office16\OART.dll"
REGSVR32 /s "Office16\OSF.dll"
REGSVR32 /s "Office16\CHART.DLL"
REGSVR32 /s "Office16\MSADDNDR.dll"
PUSHD %~DP0system
FOR %%i in (*.*) do IF Not Exist %SYSPath%\%%i COPY /y %%i %SYSPath% >nul 2>nul
REGSVR32 /s "%SYSPath%\FM20.DLL"
POPD
set route=%cd%
set route=%route:\=\\%
copy "office16\office.dat" "%temp%\test.dat" /y >nul 2>nul
"%~dp0ospp\fr.exe" "%temp%\test.dat" -fic:"C:\\" -t:"%SystemDrive%\\"
"%~dp0ospp\fr.exe" "%temp%\test.dat" -fic:"D:\\office2016" -t:"%route%"
IF /i %ARCH%==X86 (
   "%~dp0ospp\fr.exe" "%temp%\test.dat" -fic:"SysWOW64" -t:"system32"
   "%~dp0ospp\fr.exe" "%temp%\test.dat" -fic:"Program Files (x86)" -t:"Program Files"
   "%~dp0ospp\fr.exe" "%temp%\test.dat" -fic:"\Wow6432Node" -t:""
)
regedit /s "%temp%\test.dat"
del /q "%temp%\test.dat"
regedit /s "office16\officeu.dat"
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Word 2016.lnk""):b.TargetPath=""%CD%\Office16\WINWORD.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")&SET E=完成!
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Excel 2016.lnk""):b.TargetPath=""%CD%\Office16\EXCEL.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")&SET E=完成!
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\PowerPnt2016.lnk""):b.TargetPath=""%CD%\Office16\POWERPNT.EXE"":b.WorkingDirectory=""%~dp0"":b.Save:close")&SET E=完成!
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Access2016.lnk""):b.TargetPath=""%CD%\Office16\MSACCESS.EXE"":b.WorkingDirectory=""%~dp0"":b.Save:close")&SET E=完成!
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00006109110000000000000000F01FEC\Features" /f /v "ProductFiles" /t REG_SZ /d ""
if NOT EXIST "%windir%\fonts\cambria.ttf" "%~dp0ospp\fontinst.exe"
if NOT EXIST "%APPDATA%\Microsoft\Office" md "%APPDATA%\Microsoft\Office"
copy "Office16\MSO0127.acl" "%APPDATA%\Microsoft\Office\MSO0127.acl" /y >nul 2>nul
if not EXIST "%APPDATA%\Microsoft\Document Building Blocks\2052\16" md "%APPDATA%\Microsoft\Document Building Blocks\2052\16" >nul 2>nul
copy "Office16\page.dotx" "%APPDATA%\Microsoft\Document Building Blocks\2052\16\Built-In Building Blocks.dotx" /y >nul 2>nul
reg add "HKCU\Software\Microsoft\Office\16.0\PowerPoint\RecentFolderList" /f /v "SoundDir" /t REG_EXPAND_SZ /d "%cd%\Office16\MEDIA\\"
echo [Version]>%temp%\re.inf
echo Signature="$CHICAGO$">>%temp%\re.inf
echo [Defaultinstall]>>%temp%\re.inf
RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 %temp%\re.inf
del /q %temp%\re.inf
IF /i %winos%==win7os goto OSPP
SET MAK=0
SET LIC=0
CSCRIPT.exe //nologo Office16\ospp.vbs /dstatus | FIND.exe "Office 16, Office16ProPlusVL_" && SET MAK=1
CSCRIPT.exe //nologo Office16\ospp.vbs /dstatus | FIND.exe "Office 16, Office16ProPlusVL_" || SET MAK=0
IF %MAK% EQU 1 (
    CSCRIPT.exe //nologo Office16\ospp.vbs /dstatus | FIND.exe "---LICENSED---" && SET LIC=1
    CSCRIPT.exe //nologo Office16\ospp.vbs /dstatus | FIND.exe "---LICENSED---" || SET LIC=0
)
SET /a VLinfo=%MAK%+%LIC% 2>nul
IF "%VLinfo%" EQU "2" (
    echo    OFFICE处于已激活状态！
    exit
)
set key=%WINDIR%\System32\spp\store
IF EXIST "%WINDIR%\System32\spp\store\2.0" (set key=%WINDIR%\System32\spp\store\2.0)
IF EXIST "%WINDIR%\System32\spp\store_test" (set key=%WINDIR%\System32\spp\store_test\2.0)
net stop sppsvc
icacls %key%\* /save %Temp%\AclFile /T
icacls "%key%" /grant Everyone:F /t
SET REP=1
attrib -h "%key%\data.dat"
IF NOT EXIST "%key%\2016Bak" (
  xcopy /y /h "%key%\*.dat" "%key%\2016Bak\"
  xcopy /y /h "%key%\cache\*.dat" "%key%\2016Bak\cache\"
)
copy "ospp\tokens.dat" "%key%\tokens.dat" /y>nul || SET REP=0
copy "ospp\data.dat" "%key%\data.dat" /y>nul || SET REP=0
attrib +h "%key%\data.dat"
icacls %key%\ /restore %Temp%\AclFile /T && DEL /f /q %Temp%\AclFile
IF "%REP%" EQU "1" (
    ECHO  原始激活信息文件备份在 %key%\2016Bak 文件夹中！
) ELSE (
cls
color 4F
echo.
echo.
echo.           ★★★　警告！！！激活文件被占用，复制文件出错！ ★★★
echo.
echo.
echo     原始激活信息文件备份在 %key%\Bak 文件夹中 ！
echo.
echo.
echo  　 请手动停止sppsvc服务，并将 ospp 文件夹下tokens.dat、data.dat文件
echo.
echo.
echo　　 复制到 %key% 文件夹中替换对应文件，
echo.
echo.
echo  　 成功替换两个文件后，再用 kms 等工具激活 office ，否则会闪退！
echo.
echo.
pause>nul
exit
)
cls
cd kms
echo  安装已完成，正在进行kms激活……
KMS.cmd
exit

:OSPP
copy "ospp\ospp.dat" "%temp%\ospp.reg" /y
set osppreg=%ProgramFiles:\=\\%
"%~dp0ospp\fr.exe" "%temp%\ospp.reg" -fic:"C:\\Program Files" -t:"%osppreg%"
regedit /s "%temp%\ospp.reg"
del /f /q "%temp%\ospp.reg"
IF /i %ARCH%==X64 (
    "%~dp0ospp\7za.exe" x -y "ospp\OSPP_X64.7z" -o"%CommonProgramFiles%\Microsoft Shared" >nul 2>nul
    "%~dp0ospp\7za.exe" x -y "ospp\OSPP_X64(X86).7z" -o"%CommonProgramFiles(x86)%\Microsoft Shared" >nul 2>nul
) ELSE (
    "%~dp0ospp\7za.exe" x -y "ospp\OSPP_X86.7z" -o"%CommonProgramFiles%\Microsoft Shared" >nul 2>nul
)
net localgroup administrators "Network Service" /add
set "ospppath=%CommonProgramFiles%\Microsoft Shared\OfficeSoftwareProtectionPlatform"
set "osppdata=%AllUsersProfile%\Microsoft\OfficeSoftwareProtectionPlatform"
mofcomp "%ospppath%\OSPPWMI.MOF"
REGSVR32 /s "%ospppath%\OSPPWMI.dll"
IF NOT EXIST "%osppdata%" (md "%osppdata%" && md "%osppdata%\Cache")
copy "ospp\tokens7.dat" "%osppdata%\tokens.dat" /y
copy "ospp\cache.dat" "%osppdata%\Cache\cache.dat" /y
sc create osppsvc start= DEMAND obj= "NT AUTHORITY\NetworkService" Binpath= "%ospppath%\OSPPSVC.exe" DisplayName= "Office Software Protection Platform" Depend= RpcSs
sc Description osppsvc "微软office正版验证程序"
sc sdset osppsvc "D:(A;;CCLCSWRPLO;;;NS)(A;;CCLCSWRPLO;;;IU)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;SU)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)"
"%~dp0office16\OSPPREARM.EXE"
exit
