@echo off
if exist "%SystemRoot%\SysWOW64" path %path%;%p%\SysNative;%SystemRoot%\SysWOW64;%~dp0
bcdedit >nul
if '%errorlevel%' NEQ '0' (goto UACPrompt) else (goto UACAdmin)
:UACPrompt
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit

:UACAdmin
TITLE 注册 WPS
mode con cols=50 lines=20
color 2F

ECHO 　　　正在绿化中..请稍等..
taskkill /f /im et*>NUL 2>NUL
taskkill /f /im wpp*>NUL 2>NUL
taskkill /f /t /im wps*>NUL 2>NUL
taskkill /f /im wpscloudsvr*>NUL 2>NUL


cd /d "%~dp0"
::-------------------ksomisc.exe配置文件---------------------------------
if not exist "%~dp0utility" md "%~dp0utility"
(
echo [installinfo]
echo common=1
echo wps=1
echo wpp=1
echo et=1
echo template=1
echo assoword=0
echo assoexcel=0
echo assopowerpnt=0
echo savetomso=1
echo desktopshortcuts=0
echo startmenudir=WPS Office 专业版
echo theme=0
echo cloudusbdriveshortcut=0
echo vba=1
echo compatiblemso=1
echo assopdf=0
echo assopic=0
echo assopic2=0
echo [version]
echo display=Professional
echo [modulestate]
echo wps=1
echo wpp=1
echo et=1
echo pdf=0
echo [localInfo]
echo uselocal=156
echo instlanguage=2052
echo [diffPatch]
echo down=0
echo [languagePack]
echo zh_CN=1
)>utility\install.ini 


::--------------------------------------------------------------------------------------
cd /d "%~dp0office6"

echo 微软输入法突然不显示选字框解决方法：
echo 语言首选项-微软拼音-选项-常规-兼容性-开启

echo 开启兼容性
reg add "HKLM\SOFTWARE\Microsoft\Input\Locales" /f /v "InputLocale" /t REG_DWORD /d 1705988
reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Input\Locales" /f /v "InputLocale" /t REG_DWORD /d 1705988
reg add "HKCU\SOFTWARE\Microsoft\CTF\TIP\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}" /f /v "DummyValue" /t REG_DWORD /d 1
reg add "HKCU\SOFTWARE\Microsoft\Input\TSF\Tsf3Override\{81d4e9c9-1d3b-41bc-9e6c-4b40bf79e35e}" /f /v "NoTsf3Override2" /t REG_DWORD /d 1


::===========================修正某些版本新建模板问题===================================================
if exist "%~dp0office6\mui\zh_CN\templates\newfile.xlsx" reg add "HKCR\.xlsx\Excel.Sheet.12\shellNew" /f /v "FileName" /t REG_SZ /d "%~dp0office6\mui\zh_CN\templates\newfile.xlsx"
if exist "%~dp0office6\mui\zh_CN\templates\newfile.xls" reg add "HKCR\.xls\Excel.Sheet.8\shellNew" /f /v "FileName" /t REG_SZ /d "%~dp0office6\mui\zh_CN\templates\newfile.xls"
if exist "%~dp0office6\mui\zh_CN\templates\newfile.pptx" reg add "HKCR\.pptx\PowerPoint.Show.12\shellNew" /f /v "FileName" /t REG_SZ /d "%~dp0office6\mui\zh_CN\templates\newfile.pptx"
if exist "%~dp0office6\mui\zh_CN\templates\newfile.ppt" reg add "HKCR\.ppt\PowerPoint.Show.8\shellNew" /f /v "FileName" /t REG_SZ /d "%~dp0office6\mui\zh_CN\templates\newfile.ppt"
if exist "%~dp0office6\mui\zh_CN\templates\newfile.docx" reg add "HKCR\.docx\Word.Document.12\shellNew" /f /v "FileName" /t REG_SZ /d "%~dp0office6\mui\zh_CN\templates\newfile.docx"
if exist "%~dp0office6\mui\zh_CN\templates\newfile.doc" reg add "HKCR\.doc\Word.Document.8\shellNew" /f /v "FileName" /t REG_SZ /d "%~dp0office6\mui\zh_CN\templates\newfile.doc"
::==================================处理结束===========================================================


::设置默认语言
ksomisc.exe -setlng 2052
::注册DejaVuMathTeXGyre.ttf字体
ksomisc.exe -regmtfont

::添加序列号
ksomisc.exe -addsn TJ3GN-9NTGQ-GLF7C-YEN8X-TJWML
ksomisc.exe -addsn THUV2-32HH7-6NMHN-PTX7Y-QQCTH
ksomisc.exe -addsn GL9QG-DNC62-6LCMG-DRQTL-QR9HD

::注册类（classes）、类ID（CLSID）、接口、typelib、路径、软件信息等
ksomisc.exe -register

::二选一  -setappcapk（wps的Progid） -compatiblemso（msoffice Progid）
::设置mso格式为 msoffice Progid
ksomisc.exe -compatiblemso

::保存为ms office格式
ksomisc.exe -saveas_mso

::注册kdcsdk.dll
ksomisc.exe -addJsapiCert


::创建桌面快捷方式
rem ksomisc.exe -createlink desktop
::重建图标缓存
ksomisc.exe -rebuildicon
::-------------------------------------------------------------------------
::防止oem.ini某些参数影响ksomisc指令执行，重复执行一次




set "pdd=%~dp0office6\cfgs\product.dat"
set "oin=%~dp0office6\cfgs\oem.ini"




move /y "%pdd%" "%pdd%.bak"
copy /y "%~dp0office6\cfgs\products.dat" "%~dp0office6\cfgs\product.dat"
move /y "%oin%" "%oin%.bak"


cd /d "%~dp0office6"

::添加序列号
ksomisc.exe -addsn TJ3GN-9NTGQ-GLF7C-YEN8X-TJWML
ksomisc.exe -addsn THUV2-32HH7-6NMHN-PTX7Y-QQCTH
ksomisc.exe -addsn GL9QG-DNC62-6LCMG-DRQTL-QR9HD

::二选一  -setappcapk（wps的Progid） -compatiblemso（msoffice Progid）
::设置mso格式为 msoffice Progid
ksomisc.exe -compatiblemso
::-------------------------------------------------------------------------

::echo 显示的路径不能有括号，否则出错，需处理一下
set tp=
for /f "tokens=1-2,* delims= " %%a in ('reg query "HKCR\.pdf\wps\shellnew\ShellNew" /f "Command"^|findstr /i /l "REG_SZ"') do set tp=%%~c


set "tp=%tp:"=%"
set "tp=%tp:"=%"
if "%tp%" equ "=" goto :sadufhowfkhsdagfo
set "tp=%tp:(=^(%"
set "tp=%tp:)=^)%"

for /f "tokens=1,* delims=/" %%a in ('echo "%tp%"') do set "tp=%%~dpa"

if not exist "%tp%office6\wpspdf.exe" reg delete "HKCR\.pdf\wps\shellnew" /f 2>nul
:sadufhowfkhsdagfo


::重建图标缓存
ksomisc.exe -rebuildicon
::-----------------------------------------------------------------------
move /y "%oin%.bak" "%oin%"
move /y "%pdd%.bak" "%pdd%"
::===========================ksomisc处理结束===================================================


rd /s /q "%AppData%\Kingsoft\office6" 2>NUL
rd /s /q "%AppData%\Kingsoft\wps" 2>NUL
del /f /q "%AppData%\Kingsoft\wps" 2>NUL
rd /s /q "%AppData%\Kingsoft\kaccountsdk" 2>NUL
rd /s /q "%AppData%\Kingsoft\kdynsdk" 2>NUL
rd /s /q "%LocalAppData%\Kingsoft\WPS Cloud Files" 2>NUL

sc delete wpscloudsvr >NUL 2>NUL
reg delete HKCU\Software\Kingsoft\wpscloud /F >NUL 2>NUL


::-------------------------最大化--------------------------------------------------------------------------------------------
reg add "HKCU\Software\Kingsoft\Office\6.0\et\Application Settings" /f /v "WindowIsMaximized" /t REG_SZ /d "true"
reg add "HKCU\Software\Kingsoft\Office\6.0\wpp\Application Settings" /f /v "WindowIsMaximized" /t REG_SZ /d "true"
reg add "HKCU\Software\Kingsoft\Office\6.0\wps\Application Settings" /f /v "WindowIsMaximized" /t REG_SZ /d "true"

::-------------------------双击关闭标签的功能--------------------------------------------------------------------------------
reg add "HKCU\Software\kingsoft\Office\6.0\et\Application Settings" /f /v "Option_TabCloseByDblClick" /t REG_SZ /d "true"
reg add "HKCU\Software\kingsoft\Office\6.0\wps\Application Settings" /f /v "Option_TabCloseByDblClick" /t REG_SZ /d "true"
reg add "HKCU\Software\kingsoft\Office\6.0\wpp\Application Settings" /f /v "Option_TabCloseByDblClick" /t REG_SZ /d "true"


cd /d "%~dp0"
::-------------------------common-------------------------------------------------------------------------
reg add "HKCU\Software\Kingsoft\Office" /f /v "languages" /t REG_SZ /d "zh_CN"
reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\Common" /f /v "InstallRoot" /t REG_SZ /d "%CD%"

reg add "HKCU\Software\Kingsoft\Office\6.0\common" /f /v "DefaultLanguage" /t REG_DWORD /d 2052
reg add "HKCU\Software\Kingsoft\Office\6.0\common\Local" /f /v "UILanguage" /t REG_DWORD /d 2052

reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\Common" /f /v "do_not_detect_file_association_while_startup" /t REG_SZ /d "true"
reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\Common\updateinfo" /f /v "ForceUpdateOnStart" /t REG_SZ /d "false"
	

::----------------写入注册信息，以取消首次启动时的对话框-------------------------------------------------------------------------------------------------
reg add "HKCU\Software\Kingsoft\Office\6.0\common" /f /v "AcceptedEULA" /t REG_SZ /d "true"
reg add "HKLM\SOFTWARE\WOW6432Node\Kingsoft\Office\6.0\Common" /f /v "hostprocname" /t REG_SZ /d "wpsoffice.exe"
Reg add "HKLM\SOFTWARE\WOW6432Node\Kingsoft\Office\6.0\Common" /f /v "do_not_detect_file_association_while_startup" /t REG_SZ /d "true"



::-------------------------oem信息，可自行更改---------------------------------------------------------------------------------------------------------------
Reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\common\UserInfo" /f /v "UserName" /t REG_SZ /d "wps"
Reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\common\UserInfo" /f /v "Company" /t REG_SZ /d "金山软件"
Reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\common\UserInfo" /f /v "Abbreviation" /t REG_SZ /d "Admin"
Reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\common\UserInfo" /f /v "LocateUserHaveSet" /t REG_DWORD /d "1"

reg add "HKCU\Software\Kingsoft\Office\6.0\Common" /f /v "WindowCount" /t REG_DWORD /d 0
reg add "HKCU\Software\Kingsoft\Office\6.0\Common\kdcinfoc\sdkpath" /f /v "path" /t REG_SZ /d "%~dp0office6\addons\kdcsdk\kdcsdk.dll"


::不自动切换皮肤
reg add "HKCU\SOFTWARE\Kingsoft\Office\6.0\Common" /f /v "autoSwitchSkin" /t REG_SZ /d "false"
::多组件模式
reg add "HKCU\Software\Kingsoft\Office\6.0\wpsoffice\Application Settings" /f /v "AppComponentMode" /t REG_SZ /d "prome_independ"



md "%AppData%\Kingsoft\office6" 2>NUL
md "%AppData%\Kingsoft\office6\customui" 2>NUL
cd /d "%AppData%\Kingsoft\office6\customui" 2>NUL
echo [common]>ui.ini 2>NUL
echo qatUsed=true>>ui.ini 2>NUL
md "%LocalAppData%\Kingsoft\WPS Cloud Files\userdata\qing" 2>NUL
cd /d "%LocalAppData%\Kingsoft\WPS Cloud Files\userdata\qing" 2>NUL
echo [General]>config.ini 2>NUL
echo autologin=1 >>config.ini 2>NUL


cd /d "%~dp0"



::---文件-选项=自定义功能区-安全---复选框选择打开或关闭---------------------------------------------------
if exist utility\customui xcopy /s /q /y /r utility\customui "%appdata%\Kingsoft\office6\customui\"



::-----------------------vba开发环境---------------------------------
::检查是否需要安装vba环境
for /f "tokens=2,*" %%a in ('reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\VBA" /v "Vbe6DllPath"  2^>nul') do set wv=%%b
if not exist "%wv%" (
	"%~dp0utility\wps.vba7.exe"
	reg add "HKCU\SOFTWARE\Classes\TypeLib\{0002E157-0000-0000-C000-000000000046}\5.3\0\win32" /f /ve /t REG_SZ /d "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA7\VBE6EXT.OLB"
	rem echo 修正路径
	if exist "C:\Program Files\Common Files (x86)\microsoft shared\VBA\VBA7\VBE7.DLL" reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\VBA" /f /v "Vbe71DllPath" /t REG_SZ /d "C:\Program Files\Common Files (x86)\microsoft shared\VBA\VBA7\VBE7.DLL"

)

::-------------------------注册公式编辑器字体------------------------------------------------------------
set mtf=
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" 2^>nul ^|findstr /i /l "MT Extra"') do set mtf=%%a
if "%mtf%" equ "" (
	reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /f /v "MT Extra (TrueType)" /t REG_SZ /d "%~dp0office6\mui\default\resource\ksee\Fonts\TrueType\mtextra.ttf"
	RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
)

::公式编辑器初始化
set "ee=%~dp0office6\mui\default\resource\ksee\EqnEdit.exe"
if not exist "%ee%" set "ee=%~dp0office6\mui\zh_CN\resource\ksee\EqnEdit.exe"
if exist "%ee%" start "" "%ee%"
timeout /t 1
taskkill /f /im EqnEdit*>NUL 2>NUL


::安装Access数据库引擎
cd /d "%~dp0"
set ade=
for /f "tokens=*" %%a in ('dir /b /s /a-d utility\AccessDatabaseEngine*.*') do set ade=%%a

set msdbe=0
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\Classes\Installer\Products" 2^>nul ^|findstr /i /l "000041091D0040800000000000F01FEC"') do set msdbe=1
if "%msdbe%" equ "0" "%ade%" /passive




if exist "%~dp0wps-msoffice-共存关联.cmd" call "%~dp0wps-msoffice-共存关联.cmd"
if exist "%~dp0皮肤v3pro-切换2greeny.cmd" call "%~dp0皮肤v3pro-切换2greeny.cmd"
if exist "%~dp0WPS_预览插件.cmd" call "%~dp0WPS_预览插件.cmd"

cd /d "%~dp0"
::--------------------------创建快捷方式-----------------------------------------------------------------------------------------------------------------------
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(""%PUBLIC%\Desktop\WPS文字 Pro.lnk""):b.TargetPath=""%~dp0office6\wps.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(""%PUBLIC%\Desktop\WPS演示 Pro.lnk""):b.TargetPath=""%~dp0office6\wpp.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(""%PUBLIC%\Desktop\WPS表格 Pro.lnk""):b.TargetPath=""%~dp0office6\et.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")

if not exist "%appdata%\Microsoft\Internet Explorer\Quick Launch\办公工具"  md "%appdata%\Microsoft\Internet Explorer\Quick Launch\办公工具\"
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(""%appdata%\Microsoft\Internet Explorer\Quick Launch\办公工具\WPS文字 Pro.lnk""):b.TargetPath=""%~dp0office6\wps.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(""%appdata%\Microsoft\Internet Explorer\Quick Launch\办公工具\WPS演示 Pro.lnk""):b.TargetPath=""%~dp0office6\wpp.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(""%appdata%\Microsoft\Internet Explorer\Quick Launch\办公工具\WPS表格 Pro.lnk""):b.TargetPath=""%~dp0office6\et.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")