@echo off
:Init
Title 搜狗拼音
MODE con: Cols=40 Lines=11

:BatchGotAdmin
:--------------------------------------
Set "_Args=%* "
if `%1` neq `` Set "_Args=%_Args:"=""%"
fltmc 1>nul 2>nul||mshta VBScript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c """"%~f0"" %_Args%""",,"runas",1)(Window.Close) 2>nul&&Exit /b
Pushd "%CD%"&cd /d "%~dp0"
:--------------------------------------

:Begin
Set "SGver=10.5.0.4737"
Set "SGnop=替换无执行文件"
cd %SGver%
taskkill /f /im SGTool.exe /t 1>nul 2>nul
if not ErrorLevel 1 _Green\Sleep.vbs 2000 1>nul 2>nul||Call :Delay 2
if defined SGnop copy /y SGTool.bak SGTool.exe 1>nul 2>nul

:UnInsta
Call :Xecho "8f.:正在卸载中，请稍候。。。"
SGTool.exe --appid=install -u 1>nul 2>nul
Regsvr32 /s /u "%CD%\SogouTSF.dll"
Regsvr32 /s /u "%WinDir%\System32\SogouTSF.ime"
Regsvr32 /s /u "%WinDir%\SysWOW64\SogouTSF.ime"
reg delete "HKLM\SOFTWARE\SogouInput" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\SogouComponents" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\SogouInput" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\SogouComponents" /f 1>nul 2>nul
reg delete "HKCU\SOFTWARE\SogouInput" /f 1>nul 2>nul
reg delete "HKCU\SOFTWARE\SogouInput.ppup" /f 1>nul 2>nul
reg delete "HKCU\SOFTWARE\SogouInput.user" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\.scel" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\.ssf" /f 1>nul 2>nul
reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.scel" /f 1>nul 2>nul
reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ssf" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\SogouCellDict" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\SogouSkinFile" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\CLSID\{CC43AF26-60C3-4612-B58D-27A07A40E90B}" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\CLSID\{E7EA138E-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{CC43AF26-60C3-4612-B58D-27A07A40E90B}" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{E7EA138E-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Microsoft\CTF\TIP\{CC43AF26-60C3-4612-B58D-27A07A40E90B}" /f 1>nul 2>nul
reg delete "HKLM\SOFTWARE\Microsoft\CTF\TIP\{E7EA138E-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
reg delete "HKCU\SOFTWARE\Microsoft\CTF\TIP\{CC43AF26-60C3-4612-B58D-27A07A40E90B}" /f 1>nul 2>nul
reg delete "HKCU\SOFTWARE\Microsoft\CTF\TIP\{E7EA138E-69F8-11D7-A6EA-00065B844310}" /f 1>nul 2>nul
for /f "tokens=2*" %%i in ('reg query "HKCU\EUDC\936" /v "SGPYBackupSystemDefaultEUDCFont" 2^>nul') do Set "EUDC=%%j"
if not defined EUDC Set EUDC=EUDC.TTE
reg add "HKCU\EUDC\936" /f /v "SystemDefaultEUDCFont" /t REG_SZ /d "%EUDC%" 1>nul 2>nul
reg delete "HKCU\EUDC\936" /f /v "SGPYBackupSystemDefaultEUDCFont" 1>nul 2>nul
for /f "tokens=2*" %%i in ('reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop" 2^>nul') do Set "Desktop=%%j"
del /q "%Desktop%\属性设置.lnk" 1>nul 2>nul
del /q "%Desktop%\输入法管理器.lnk" 1>nul 2>nul
del /q "%Desktop%\符号大全.lnk" 1>nul 2>nul
del /q "%Desktop%\流行诗词.lnk" 1>nul 2>nul
del /q "%~dp0属性设置.lnk" 1>nul 2>nul
del /q "%~dp0输入法管理器.lnk" 1>nul 2>nul
del /q "%~dp0符号大全.lnk" 1>nul 2>nul
del /q "%~dp0流行诗词.lnk" 1>nul 2>nul
:: rd /s /q "..\Components" 1>nul 2>nul
:: rd /s /q "..\SogouExe" 1>nul 2>nul
rd /s /q "%UserProfile%\AppData\LocalLow\SogouPY" 1>nul 2>nul
rd /s /q "%UserProfile%\AppData\LocalLow\SogouPY.users" 1>nul 2>nul
rd /s /q "%APPDATA%\SogouPY" 1>nul 2>nul
rd /s /q "%APPDATA%\SogouPY.users" 1>nul 2>nul
rd /s /q "%ALLUSERSPROFILE%\SogouInput" 1>nul 2>nul
rd /s /q "%WinDir%\System32\IME\SogouPY" 1>nul 2>nul
rd /s /q "%WinDir%\SysWOW64\IME\SogouPY" 1>nul 2>nul
del /f /q "%CD%\sgim_charvalid.bin" 1>nul 2>nul
del /f /q "%CD%\sgim_charvalid_tmp.bin" 1>nul 2>nul
del /f /q "%CD%\sgim_core.bin" 1>nul 2>nul
del /f /q "%WinDir%\System32\SogouPY.ime" 1>nul 2>nul
del /f /q "%WinDir%\System32\SogouTSF.ime" 1>nul 2>nul
del /f /q "%WinDir%\SysWOW64\SogouPY.ime" 1>nul 2>nul
del /f /q "%WinDir%\SysWOW64\SogouTSF.ime" 1>nul 2>nul

:End
taskkill /f /im SGTool.exe /t 1>nul 2>nul
for %%i in ("%WinDir%\System32\SogouPY.ime" "%WinDir%\SysWOW64\SogouPY.ime") do if exist %%i Set /a Installed+=1
if "%Installed%" gtr "0" Call :Xecho "4f.:文件被占用，请重启后再卸载一次！！"&Call :Delay 5 +
Exit /b

:Delay
REM 延迟操作，参数1：延迟秒数，参数2：+为显示倒计时
if `%2` == `+` (Set n=2) else Set n=1
if exist %WINDIR%\System32\timeout.exe (timeout /t %1 %n%>nul) else if exist %WINDIR%\System32\choice.exe (choice /t %1 /d y /n >nul) else ping 127.1 -n %1 >nul
Goto :eof

:Xecho
REM 显示彩色文字，不支持半角字符 \ / : * ? " < > | . % ! ~
setlocal enabledelayedexpansion
Set echox=EchoX.exe&&!echox! 1>nul 2>nul||Set echox=
for %%a in (%*) do (
    Set "param=%%a"&Set "param=!param:"=!"
    Set n=0&(if "!param:~2,2!" == "::" Set /a n+=1)&(if "!param:~2,2!" == ".:" Set /a n+=1)
    if !n! gtr 0 (
        if /i "!param:~0,2!" == "xx" (Set /p="_!param:~4!"<nul) else (Set param=%%~nxa&if defined echox (!echox! -c !param:~0,2! -n "!param:~4!") else (Pushd "%TEMP%"&>"!param:~4!",Set /p= <nul&findstr /a:!param:~0,2! .* "!param:~4!*"&del "!param:~4!"&Popd))
        if "!param:~2,1!" == "." echo.
    ) else if defined param Set /p="_!param!"<nul
)
endlocal
Goto :eof