@echo off
if /i "%UserName%" == "SYSTEM" (Set PE=1&Goto GotAdmin) else (reg query "HKLM\SYSTEM\ControlSet001\Control\MiniNT" 1>nul 2>nul&&(Set PE=1&Goto GotAdmin))
:BatchGotAdmin
Set _Args=%*
if `%1` neq `` Set "_Args=%_Args:"=""%"
if exist %WinDir%\System32\fltMC.exe fltMC 1>nul 2>nul||mshta VBScript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c """"%~f0"" %_Args%""",,"runas",1)(Window.Close) 2>nul&&Exit /b

:GotAdmin
Pushd "%CD%"&cd /d "%~dp0"
REM 设置安装参数
Set "SGV=5.5.0.2585"
Set "SGN=搜狗五笔拼音"
Set "EXE=InstallIme"
Set "SGusr=用户数据" :: 设置配置文件路径：为当前路径的“用户数据”文件夹 (要求系统分区必须是 NTFS 分区)
if not defined SGusr if exist "用户数据\SogouPY\env.ini" Set "SGusr=用户数据"
REM 判断启动条件
find /? 1>nul 2>nul&&Set "findstr=find /i "||Set findstr=
findstr /? 1>nul 2>nul&&Set "findstr=findstr /i /c:"
if not defined findstr Color cf&echo 找不到 find.exe 文件，按任意键退出 。。。&Pause >nul&Exit /b
REM 判断输入参数
Set hint=&Set "Green=%SGV%\_Green"&Set "IME=%SGV%\_Green\IME"
if /i "%~x1" == ".scel" Call :ScelSsf ScdReg %1&Exit /b
if /i "%~x1" == ".ssf" Call :ScelSsf SkinReg %1&Exit /b
if /i "%~1" == "install" Goto Install
if /i "%~1" == "onceins" Goto Install
REM 窗口设置
Title 安装&(if exist %WinDir%\System32\ureg.dll Mode 36,9 2>nul)&Color 2f
Set hint=启用提示

:Install
if defined hint echo 正在安装中，请稍候 。。。
REM 系统环境
:: if exist "%WinDir%\System32\cryptui.dll" %Green%\CertMgr.exe /add %Green%\MyCert.cer /s /r localMachine root /all 1>nul 2>nul
Cacls . 1>nul 2>nul&&Set "Cacls=Cacls"||Set "Cacls=%Green%\Cacls"
iCacls /? 1>nul 2>nul&&Set "iCacls=iCacls"||Set "iCacls=%Green%\iCacls"
if exist ".\%SGV%" (
    %iCacls% . /SetintegrityLevel l 1>nul 2>nul
    echo y|%Cacls% . /t /e /c /p "Everyone":r 1>nul 2>nul
    echo y|%Cacls% . /t /e /c /p "Users":r 1>nul 2>nul
    echo y|%Cacls% . /t /e /c /p "ALL APPLICATION PACKAGES":r 1>nul 2>nul
    echo y|%Cacls% . /t /e /c /p "SYSTEM":f 1>nul 2>nul
    echo y|%Cacls% . /t /e /c /p "Administrators":f 1>nul 2>nul
)
tskill /? 1>nul 2>nul&&Set "TsKill=tskill"||if exist "%Green%\TsKill.exe" (Set "TsKill=%Green%\TsKill") else Set "TsKill=Pecmd KILL"
reg query "HKCU\Keyboard Layout\Substitutes"|%findstr%"REG_SZ" 1>nul 2>nul&&(
    reg delete "HKCU\Keyboard Layout\Substitutes" /f 1>nul 2>nul&&reg add "HKCU\Keyboard Layout\Substitutes" /f 1>nul 2>nul
    %TsKill% ctfmon 1>nul 2>nul
    @start "" /d %WinDir%\System32 ctfmon 1>nul 2>nul
)
REM 输入法环境
if defined CommonProgramW6432 (Set sys=%SystemRoot%\SysWOW64&Set xcpu=WOW6432Node\) else (Set sys=%SystemRoot%\System32&Set xcpu=)
Set OldOS=&Set "SGData=%UserProfile%\AppData\LocalLow"
ver|%findstr%" 5." 1>nul 2>nul&&(Set OldOS=1&Set "SGData=%AppData%"&Set "SGusr=")
ver|%findstr%" 6.0" 1>nul 2>nul&&Set OldOS=1
ver|%findstr%" 6.1" 1>nul 2>nul&&Set OldOS=1
:: if not defined CommonProgramW6432 Set OldOS=1
rd /s /q "%SGData%\SogouWB" 1>nul 2>nul&rd /s /q "%SGData%\SogouWB.users" 1>nul 2>nul
Set err_n=0&if defined SGusr (
    mkdir "%SGusr%\SogouWB" 2>nul&mkdir "%SGusr%\SogouWB.users" 2>nul
    if not exist "%SGusr%\SogouWB\env.ini" (copy /y "%IME%\*.bin" "%SGusr%\SogouWB\" 1>nul 2>nul&copy /y "%IME%\env_wb.ini" "%SGusr%\SogouWB\env.ini" 1>nul 2>nul&copy /y "%IME%\wbskin_v3.dat" "%SGusr%\SogouWB\wbskin_v3.dat" 1>nul 2>nul)
    mklink /d "%SGData%\SogouWB" "%~dp0%SGusr%\SogouWB" 1>nul 2>nul||Set /a err_n+=1
    mklink /d "%SGData%\SogouWB.users" "%~dp0%SGusr%\SogouWB.users" 1>nul 2>nul||Set /a err_n+=1    
) else (
    mkdir "%SGData%\SogouWB" 2>nul
    copy /y "%IME%\*.bin" "%SGData%\SogouWB\" 1>nul 2>nul
    copy /y "%IME%\env_wb.ini" "%SGData%\SogouWB\env.ini" 1>nul 2>nul
    copy /y "%IME%\wbskin_v3.dat" "%SGData%\SogouWB\wbskin_v3.dat" 1>nul 2>nul
)
if %err_n% gtr 0 (
    rd /s /q "%SGData%\SogouWB" 1>nul 2>nul&rd /s /q "%SGData%\SogouWB.users" 1>nul 2>nul
    mkdir "%SGData%\SogouWB" 2>nul&mkdir "%SGData%\SogouWB.users" 2>nul
    copy /y "%IME%\*.bin" "%SGData%\SogouWB\" 1>nul 2>nul
    copy /y "%IME%\env_wb.ini" "%SGData%\SogouWB\env.ini" 1>nul 2>nul
    copy /y "%IME%\wbskin_v3.dat" "%SGData%\SogouWB\wbskin_v3.dat" 1>nul 2>nul
)
copy /y "%IME%\SogouWB_x64.ime" "%WinDir%\System32\SogouWB.ime" 1>nul 2>nul
copy /y "%IME%\SogouWB.ime" "%sys%\" 1>nul 2>nul
REM 输入法注册表项
reg add "HKCU\SOFTWARE\SogouWBInput" /f /ve /t REG_SZ /d "" 1>nul 2>nul
reg add "HKLM\SOFTWARE\%xcpu%SogouWBInput" /f /ve /t REG_SZ /d "%CD%" 1>nul 2>nul
reg add "HKLM\SOFTWARE\%xcpu%SogouWBInput" /f /v "Version" /t REG_SZ /d "%SGV%" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%xcpu%CLSID\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f /ve /t REG_SZ /d "%SGN%" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%xcpu%CLSID\{E7EA138F-69F8-11D7-A6EA-00065B844310}\InProcServer32" /f /ve /t REG_SZ /d "%WinDir%\SysWOW64\SogouWBTSF.ime" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%xcpu%CLSID\{E7EA138F-69F8-11D7-A6EA-00065B844310}\InProcServer32" /f /v "ThreadingModel" /t REG_SZ /d "Apartment" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\CLSID\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f /ve /t REG_SZ /d "%SGN%" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\CLSID\{E7EA138F-69F8-11D7-A6EA-00065B844310}\InProcServer32" /f /ve /t REG_SZ /d "%WinDir%\System32\SogouWBTSF.ime" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\CLSID\{E7EA138F-69F8-11D7-A6EA-00065B844310}\InProcServer32" /f /v "ThreadingModel" /t REG_SZ /d "Apartment" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%xcpu%CLSID\{CC43AF26-60C3-4612-B58D-27A07A40E90C}" /f /ve /t REG_SZ /d "SogouWB Text Service" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%xcpu%CLSID\{CC43AF26-60C3-4612-B58D-27A07A40E90C}\InProcServer32" /f /ve /t REG_SZ /d "%CD%\%SGV%\SogouTSF.dll" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%xcpu%CLSID\{CC43AF26-60C3-4612-B58D-27A07A40E90C}\InProcServer32" /f /v "ThreadingModel" /t REG_SZ /d "Apartment" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{CC43AF26-60C3-4612-B58D-27A07A40E90C}" /f /v "Enable" /t REG_SZ /d "1" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{CC43AF26-60C3-4612-B58D-27A07A40E90C}\Category\Category\{34745C63-B2F0-4784-8B67-5E12C8701A31}\{CC43AF26-60C3-4612-B58D-27A07A40E90C}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{046B8C80-1647-40F7-9B21-B93B81AABC1B}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{13A016DF-560B-46CD-947A-4C3AF1E0E35D}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{34745C63-B2F0-4784-8B67-5E12C8701A31}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{364215D9-75BC-11D7-A6EF-00065B84435C}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{364215DA-75BC-11D7-A6EF-00065B84435C}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{49D2F9CE-1F5E-11D7-A6D3-00065B84435C}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{49D2F9CF-1F5E-11D7-A6D3-00065B84435C}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Category\{CCF05DD7-4A87-11D7-A6E2-00065B84435C}\{E7EA138F-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{CC43AF26-60C3-4612-B58D-27A07A40E90C}\Category\Item\{CC43AF26-60C3-4612-B58D-27A07A40E90C}\{34745C63-B2F0-4784-8B67-5E12C8701A31}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{046B8C80-1647-40F7-9B21-B93B81AABC1B}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{13A016DF-560B-46CD-947A-4C3AF1E0E35D}" /f  1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{34745C63-B2F0-4784-8B67-5E12C8701A31}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{364215D9-75BC-11D7-A6EF-00065B84435C}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{364215DA-75BC-11D7-A6EF-00065B84435C}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{49D2F9CE-1F5E-11D7-A6D3-00065B84435C}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{49D2F9CF-1F5E-11D7-A6D3-00065B84435C}" /f 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{CCF05DD7-4A87-11D7-A6E2-00065B84435C}" /f 1>nul 2>nul
if defined OldOS (Call :AddOld) else Call :AddNew
if defined PE ( :: PE 修复 SAB3.7，输入法前空格
    reg delete "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{13A016DF-560B-46CD-947A-4C3AF1E0E35D}" /f 1>nul 2>nul 
    reg delete "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\Category\Item\{E7EA138F-69F8-11D7-A6EA-00065B844310}\{25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}" /f 1>nul 2>nul
)
REM 关联词库与皮肤文件
if exist "%SGV%\ScdReg.exe" Call :SGAssoc .scel SogouCellDict ScdReg "-add" 细胞词库
if exist "%SGV%\SkinReg.exe" Call :SGAssoc .ssf SogouSkinFile SkinReg "-install -c" 皮肤
assoc .=. 1>nul 2>nul&reg delete "HKCR\." /f 1>nul 2>nul
REM 参数处理
if `%1` == `` (Goto End) else Set "cfg=%~1"
if "%cfg:~0,1%" == "\" Set "cfg=%cfg:~1%"
if "%cfg:~0,1%" == "/" Set "cfg=%cfg:~1%"
if "%cfg:~0,1%" == "-" Set "cfg=%cfg:~1%"
if exist "%IME%\env_%cfg%.ini" copy /y "%IME%\env_%cfg%.ini" "%SGData%\SogouWB\env.ini" 1>nul 2>nul

:End
Set hint=&if /i "%~1" == "onceins" rd /s /q "%IME%" 2>nul&(for %%i in (Cacls.exe CertMgr.exe iCacls.exe InstallIme.exe MyCert.cer) do del /q "%Green%\%%~i" 2>nul)&del /q %0 2>nul
Exit /b

:SGAssoc :: 关联词库与皮肤文件 <%1=.scel,.ssf|扩展名> <%2=SogouCellDict,SogouSkinFile|注册项> <%3=ScdReg,SkinReg|注册程序> <%4=-add,-install -c|命令参数> <%5=细胞词库,皮肤|注册描述>
Set "XD=%CD%"&Set "SGParam=%~4"
Set "XD=%XD:&=^&%"
reg add "HKLM\SOFTWARE\Classes\%~1" /f /ve /t REG_SZ /d "%~2" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%~2" /f /ve /t REG_SZ /d "搜狗%~5文件" 1>nul 2>nul
reg query "HKLM\SOFTWARE\Classes\%~2\DefaultIcon" 1>nul 2>nul||reg add "HKLM\SOFTWARE\Classes\%~2\DefaultIcon" /f /ve /t REG_SZ /d "\"%XD%\%SGV%\%~3.exe\"" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%~2\Entry\SogouWB" /f /ve /t REG_SZ /d "搜狗五笔输入法" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%~2\Entry\SogouWB" /f /v "Command" /t REG_SZ /d "%CD%\%SGV%\%~3.exe" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%~2\Entry\SogouWB" /f /v "InstallType" /t REG_DWORD /d "2" 1>nul 2>nul
if /i "%~2" == "SogouSkinFile" reg add "HKLM\SOFTWARE\Classes\%~2\Entry\SogouWB" /f /v "MaxVersion" /t REG_DWORD /d "3" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%~2\Entry\SogouWB" /f /v "Params" /t REG_SZ /d "%SGParam% " 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%~2\Entry\SogouWB" /f /v "Priority" /t REG_DWORD /d "2" 1>nul 2>nul
reg query "HKLM\SOFTWARE\Classes\%~2\Shell\Open\Command" 1>nul 2>nul&&Goto :eof
reg add "HKLM\SOFTWARE\Classes\%~2\Shell\Open" /f /ve /t REG_SZ /d "安装搜狗输入法%~5" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Classes\%~2\Shell\Open\Command" /f /ve /t REG_SZ /d "\"%XD%\%SGV%\%~3.exe\" -list \"%%1\"" 1>nul 2>nul
Goto :eof

:ScelSsf :: 安装词库与皮肤文件 <%1=ScdReg,SkinReg|注册程序> <%2=file|文件路径>
Title 安装词库与皮肤文件&(if exist %WinDir%\System32\ureg.dll Mode 46,10 2>nul)&Color 2f
if exist "%SGV%\%~1.exe" @start "" "%SGV%\%~1.exe" -list %2
Goto :eof

:AddOld
reg add "HKCU\Keyboard Layout\Toggle" /f /v "hotkey" /t REG_SZ /d "3" 1>nul 2>nul
reg add "HKCU\Keyboard Layout\Toggle" /f /v "Language Hotkey" /t REG_SZ /d "3" 1>nul 2>nul
reg add "HKCU\Keyboard Layout\Toggle" /f /v "Layout Hotkey" /t REG_SZ /d "2" 1>nul 2>nul
reg add "HKU\.DEFAULT\Keyboard Layout\Toggle" /f /v "hotkey" /t REG_SZ /d "3" 1>nul 2>nul
reg add "HKU\.DEFAULT\Keyboard Layout\Toggle" /f /v "Language Hotkey" /t REG_SZ /d "3" 1>nul 2>nul
reg add "HKU\.DEFAULT\Keyboard Layout\Toggle" /f /v "Layout Hotkey" /t REG_SZ /d "2" 1>nul 2>nul
if /i "%EXE%" == "InstallIme" (%Green%\InstallIme.exe SogouWB.ime %SGN% 1>nul 2>nul&Call :AddLayouts) else (Call :AddLayouts&%Green%\IMETool.exe /add2:SogouWB.ime 1>nul 2>nul)
%Green%\IMETool.exe /move2:SogouWB.ime,1 1>nul 2>nul
%Green%\IMETool.exe /xxx 1>nul 2>nul
%Green%\IMETool.exe /move2:SogouWB.ime,99 1>nul 2>nul
Goto :eof

:AddNew
copy /y "%IME%\SogouWBTSF_x64.ime" "%WinDir%\System32\SogouWBTSF.ime" 1>nul 2>nul
copy /y "%IME%\SogouWBTSF.ime" "%sys%\" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\LanguageProfile\0x00000804\{E7EA1390-69F8-11D7-A6EA-00065B844311}" /f /v "Description" /t REG_SZ /d "%SGN%" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\LanguageProfile\0x00000804\{E7EA1390-69F8-11D7-A6EA-00065B844311}" /f /v "Enable" /t REG_DWORD /d 1 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\LanguageProfile\0x00000804\{E7EA1390-69F8-11D7-A6EA-00065B844311}" /f /v "HiddenInSettingUI" /t REG_DWORD /d 0 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\LanguageProfile\0x00000804\{E7EA1390-69F8-11D7-A6EA-00065B844311}" /f /v "IconFile" /t REG_SZ /d "%CD%\%SGV%\WbConfig.exe" 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\LanguageProfile\0x00000804\{E7EA1390-69F8-11D7-A6EA-00065B844311}" /f /v "IconIndex" /t REG_DWORD /d 0 1>nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138F-69F8-11D7-A6EA-00065B844310}\LanguageProfile\0x00000804\{E7EA1390-69F8-11D7-A6EA-00065B844311}" /f /v "SubItemInSettingUI" /t REG_DWORD /d 0 1>nul 2>nul
Call :AddLayouts
Goto :eof

:AddLayouts :: 添加输入法 Layouts
Set Layouts=&for /f "delims=" %%i in ('reg query "HKLM\SYSTEM\ControlSet001\Control\Keyboard Layouts" /s /d /f "SogouWB.ime" 2^>nul') do if not defined Layouts Set "Layouts=%%~ni%%~xi"
if /i "%Layouts:~0,1%" neq "E" Set Layouts=
if not defined Layouts reg query "HKLM\SYSTEM\ControlSet001\Control\Keyboard Layouts\E0260804" 1>nul 2>nul||Set Layouts=E0260804
if not defined Layouts Call :GetRand Layouts
reg add "HKLM\SYSTEM\ControlSet001\Control\Keyboard Layouts\%Layouts%" /f /v "Ime File" /t REG_SZ /d "SogouWB.ime" 1>nul 2>nul
reg add "HKLM\SYSTEM\ControlSet001\Control\Keyboard Layouts\%Layouts%" /f /v "Layout File" /t REG_SZ /d "kbdus.dll" 1>nul 2>nul
reg add "HKLM\SYSTEM\ControlSet001\Control\Keyboard Layouts\%Layouts%" /f /v "Layout Text" /t REG_SZ /d "%SGN%" 1>nul 2>nul
Goto :eof

:GetRand :: 获取未被占用的随机 Layouts <%1=retVar>
Set /a n1=%random%%%10&Set /a n2=%random%%%10&Set /a n3=%random%%%10
reg query "HKLM\SYSTEM\ControlSet001\Control\Keyboard Layouts\E%n1%%n2%%n3%0804" 1>nul 2>nul&&Goto GetRand||(Set "%~1=E%n1%%n2%%n3%0804"&Goto :eof)