@echo off
if not "%1"=="p1" start /min cmd.exe /c %0 p1 %1&exit

cd /d %~dp0
set "Path=%Path%;%~dp0data"
data\data.exe
data\Microsoft.NET.exe
xcopy data\ospp "%AllUsersProfile%\Microsoft\OfficeSoftwareProtectionPlatform" /e /i /q /y >nul 2>nul
xcopy data\QuickToobar "%UserProfile%\AppData\Local\Microsoft\Office" /e /i /q /y >nul 2>nul

if not "%SystemDrive%"=="X:" goto goc
"%~dp0data\fr.exe" -fr2exi "%~dp0data\office.dat" "%TEMP%\office.reg" "C:" "%SystemDrive%" "D:\\Office2010" "%CD:\=\\%"
if not EXIST "%ProgramFiles(x86)%" "%~dp0data\fr.exe" -fr2exi "%TEMP%\office.reg" "%TEMP%\office.reg" "SysWOW64" "System32" "\WOW6432Node" "" "Program Files (x86)" "Program Files" "ospp64" "ospp32"
regedit /s "%TEMP%\office.reg"

net localgroup administrators "Network Service" /add >nul 2>nul
if EXIST "%ProgramFiles(x86)%" (set "ospppath=%~dp0MShared\ospp64") ELSE (set "ospppath=%~dp0MShared\ospp32")
sc create osppsvc start= DEMAND obj= "NT AUTHORITY\NetworkService" Binpath= "%ospppath%\OSPPSVC.exe" DisplayName= "微软office正版验证程序" Depend= RpcSs >nul 2>nul
sc sdset osppsvc "D:(A;;CCLCSWRPLO;;;NS)(A;;CCLCSWRPLO;;;IU)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;SU)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)" >nul 2>nul
start /min MShared\ospp32\OSPPREARM.EXE >nul
goto goall

:goc
"%~dp0data\fr.exe" -fr2exi "%~dp0data\office.dat" "%TEMP%\office.reg" "C:" "%SystemDrive%" "D:\\Office2010" "%CD:\=\\%" ";;" ""
if not EXIST "%ProgramFiles(x86)%" "%~dp0data\fr.exe" -fr2exi "%TEMP%\office.reg" "%TEMP%\office.reg" "SysWOW64" "System32" "\WOW6432Node" "" "Program Files (x86)" "Program Files" "ospp64" "ospp32"
regedit /s "%TEMP%\office.reg"

sc query osppsvc >nul && net stop osppsvc >nul 2>nul && sc delete osppsvc >nul 2>nul
net localgroup administrators "Network Service" /add >nul 2>nul
mofcomp "%ospppath%\OSPPWMI.MOF" >nul 2>nul && REGSVR32 /s "%ospppath%\OSPPWMI.dll"
if EXIST "%ProgramFiles(x86)%" (set "ospppath=%~dp0MShared\ospp64") ELSE (set "ospppath=%~dp0MShared\ospp32")
sc create osppsvc start= DEMAND obj= "NT AUTHORITY\NetworkService" Binpath= "%ospppath%\OSPPSVC.exe" DisplayName= "微软office正版验证程序" Depend= RpcSs >nul 2>nul
sc sdset osppsvc "D:(A;;CCLCSWRPLO;;;NS)(A;;CCLCSWRPLO;;;IU)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;SU)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)" >nul 2>nul

:goall
if not EXIST %windir%\WinSxS\x86_microsoft.vc90.crt* if EXIST "%TEMP%\vcredist.exe" "%TEMP%\vcredist.exe" /q
if not EXIST %windir%\Fonts\cambria.ttf "%~dp0data\fr.exe" -FontInstall "%~dp0data\fonts"
if not EXIST "%TEMP%\no.wps" "%~dp0data\fr.exe" -fr2exi "%~dp0data\wps.dat" "%TEMP%\wps.reg" "D:\\Office2010" "%CD:\=\\%" && regedit /s "%TEMP%\wps.reg"
echo f|xcopy "%~dp0Office14\MSO0127.acl" "%APPDATA%\Microsoft\Office\MSO0127.acl" /y >nul
echo f|xcopy "%~dp0data\page.dotx" "%APPDATA%\Microsoft\Document Building Blocks\2052\14\Built-In Building Blocks.dotx" /y >nul
reg add "HKCU\Software\Microsoft\Office\14.0\PowerPoint\RecentFolderList" /f /v "SoundDir" /t REG_EXPAND_SZ /d "%~dp0Office14\MEDIA\\" >nul

if EXIST "%TEMP%\e.tmp" Start Office14\EXCEL.EXE &rd /s /q "%TEMP%\e.tmp
if EXIST "%TEMP%\P.tmp" Start Office14\POWERPNT.EXE &rd /s /q "%TEMP%\e.tmp
if EXIST "%TEMP%\w.tmp" Start Office14\WINWORD.EXE &rd /s /q "%TEMP%\w.tmp
PECMD LINK %USERPROFILE%\Desktop\Excel 2010,%~dp0Office14\EXCEL.EXE
PECMD LINK %USERPROFILE%\Desktop\PowerPnt 2010,%~dp0Office14\POWERPNT.EXE
PECMD LINK %USERPROFILE%\Desktop\Word 2010,%~dp0Office14\WINWORD.EXE
rem PECMD LINK %APPDATA%\Microsoft\Windows\Start Menu\Programs\办公文件工具\Office 2010\Excel 2010,%~dp0Office14\EXCEL.EXE
rem PECMD LINK %APPDATA%\Microsoft\Windows\Start Menu\Programs\办公文件工具\Office 2010\PowerPnt 2010,%~dp0Office14\POWERPNT.EXE
rem PECMD LINK %APPDATA%\Microsoft\Windows\Start Menu\Programs\办公文件工具\Office 2010\Word 2010,%~dp0Office14\WINWORD.EXE
rem PECMD LINK %APPDATA%\Microsoft\Windows\Start Menu\Programs\办公文件工具\Office 2010\卸载,%~dp0uninst.cmd,,imageres.dll,25
del /f /q "%TEMP%\vcredist.exe" >nul 2>nul
del /f /q "%TEMP%\*.reg" >nul 2>nul
exit

del /f /q data\data.exe >nul 2>nul
del /f /q data\Microsoft.NET.exe >nul 2>nul
del /f /q data\office.dat >nul 2>nul
del /f /q data\wps.dat >nul 2>nul
rd /s /q data\OfficeSoftwareProtectionPlatform >nul 2>nul
rd /s /q data\QuickToobar >nul 2>nul
exit
