AIGC标识 微软拼音输入法 TIP 注册修复记录

环境信息

项目
操作系统 Windows 11 Build 26200.8875
修复日期 2026-08-09

问题背景

微软拼音输入法(Microsoft Pinyin)的 TSF TIP 注册信息被完全删除,导致无法输入中文。需要从零重建 TIP 注册、CLSID 注册和语言配置文件。

官方注册方式:根据 TSF 文档,正规的 TIP 注册应通过 COM 接口完成:

  • ITfInputProcessorProfiles::Register — 注册 TIP(创建 HKLM\SOFTWARE\Microsoft\CTF\TIP\{CLSID} 键)
  • ITfInputProcessorProfiles::AddLanguageProfile — 添加语言配置文件(创建 LanguageProfile 子键)
  • ITfCategoryMgr::RegisterCategory — 注册类别(创建 Category 子键)

但在本系统中 ITfInputProcessorProfiles 的 CLSID {33F4D3C1-9F73-11d4-B4F3-00065B84435C} 未注册(REGDB_E_CLASSNOTREG),regsvr32 msctf.dll 也无法修复。因此采用直接写注册表的方式替代,二者对应关系如下:

COM API 方法 对应注册表操作
Register(clsid) 创建 HKLM\SOFTWARE\Microsoft\CTF\TIP\{clsid}
AddLanguageProfile(clsid, langid, guidProfile, desc, iconFile, iconIndex) 创建 LanguageProfile\0x{langid}\{guidProfile} 子键,写入 Description / IconFile / IconIndex
RegisterCategory(clsid, catid, guid) 创建 Category\Category\{catid}\{clsid}Category\Item\{clsid}\{catid} 子键

关键技术概念

TSF TIP 注册结构

HKLM\SOFTWARE\Microsoft\CTF\TIP\{TIP_CLSID}
├── Category
│   ├── Category\{CATEGORY_GUID}\{TIP_CLSID}   # TIP 所属类别
│   └── Item\{TIP_CLSID}\{CATEGORY_GUID}        # 反向索引
└── LanguageProfile
    └── 0x00000804\{PROFILE_GUID}               # 语言配置文件
        ├── Description          REG_SZ          # 显示名称
        ├── Display Description  REG_EXPAND_SZ  # 本地化名称(资源引用)
        ├── IconFile             REG_EXPAND_SZ  # 图标文件
        ├── IconIndex            REG_DWORD      # 图标索引
        ├── Enable               REG_DWORD      # 是否启用
        └── ProfileFlags         REG_DWORD      # 配置标志

CLSID 注册结构

HKLM\SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}
├── (Default)           REG_SZ    CImeServerChs
└── LocalServer32       # 进程外 COM 服务器(EXE)
    └── (Default)       REG_SZ    C:\Windows\System32\InputMethod\CHS\ChsIME.exe

Windows 11 Build 26200 的关键 GUID

用途 GUID
键盘输入类别 {34745C63-B2F0-4784-8B67-5E12C8701A31}
GIP 框架类别 {3AF314A2-D79F-4B1B-9992-15086D339B05}
显示属性提供者 {046B8C80-1647-40F7-9B21-B93B81AABC1B}
沉浸式支持 {13A016DF-560B-46CD-947A-4C3AF1E0E35D}
UI 元素支持 {25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}
安全模式 {49D2F9CE-1F5E-11D7-A6D3-00065B84435C}
TSF3 支持 {49D2F9CF-1F5E-11D7-A6D3-00065B84435C}
属性 UI {364215D9-75BC-11D7-A6EF-00065B84435C} / {364215DA-75BC-11D7-A6EF-00065B84435C}
额外类别 {74769EE9-4A66-4F9D-90D6-BF8B7C3EB461} / {CCF05DD7-4A87-11D7-A6E2-00065B84435C}

注意:此 build 的键盘类别 GUID 与 MSDN 文档中的 GUID_TFCAT_TIP_KEYBOARD{34745C63-B2F0-4784-8B85-9C39E1B59F3E})不同。必须检查系统中其他正常工作的 TIP 使用哪个 GUID,不能盲目照搬文档。

GIP 框架

Windows 11 使用 GIP(Generic Input Processor)框架激活 TIP。需要在 TIP 类别中添加 GIP 类别并设置 RuntimeClass

HKLM\SOFTWARE\Microsoft\CTF\TIP\{TIP_CLSID}\Category\Category\{3AF314A2-D79F-4B1B-9992-15086D339B05}
    RuntimeClass    REG_SZ    Windows.UI.Internal.Text.Core.GipFactory

Display Description 资源 ID

input.dll 中的相关字符串资源:

资源 ID 字符串
5076 中文(简体) - 微软拼音 ABC 输入风格
5090 微软注音
5091 微软拼音新体验
5107 广东拼音
5300 微软拼音

微软拼音应使用 -5300,而非 -5091(微软拼音新体验)。


修复过程

添加 Windows 语言能力

dism /online /add-capability /capabilityname:Language.Basic~~~zh-CN~0.0.1.0

获取 TrustedInstaller 权限

微软拼音的 CLSID {81D4E9C9-...} 注册表键由 TrustedInstaller 拥有,管理员默认只有 ReadKey 权限。需要通过 P/Invoke 启用 SeTakeOwnershipPrivilege,再用 .NET RegistryKey 修改所有权和权限。

# 启用权限
$privCode = @'
using System;
using System.Runtime.InteropServices;

public class Priv {
    [DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
    public static extern bool OpenProcessToken(IntPtr h, int acc, out IntPtr phtok);

    [DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
    public static extern bool LookupPrivilegeValue(string host, string name, out long pluid);

    [DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
    public static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TP newst, int len, IntPtr prev, IntPtr relen);

    [DllImport("kernel32.dll")]
    public static extern IntPtr GetCurrentProcess();

    [StructLayout(LayoutKind.Sequential, Pack=1)]
    public struct TP { public int Count; public long Luid; public int Attr; }

    public const int SE_PRIVILEGE_ENABLED = 2;
    public const int TOKEN_QUERY = 8;
    public const int TOKEN_ADJUST_PRIVILEGES = 32;

    public static bool Enable(string priv) {
        IntPtr tok;
        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, out tok)) return false;
        long luid;
        if (!LookupPrivilegeValue(null, priv, out luid)) return false;
        TP tp = new TP { Count = 1, Luid = luid, Attr = SE_PRIVILEGE_ENABLED };
        return AdjustTokenPrivileges(tok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
    }
}
'@
Add-Type -TypeDefinition $privCode
[Priv]::Enable("SeTakeOwnershipPrivilege")
[Priv]::Enable("SeRestorePrivilege")
[Priv]::Enable("SeBackupPrivilege")

# 获取 CLSID 键所有权并授予 FullControl
$subKey = "SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}"
$admin = New-Object System.Security.Principal.NTAccount("Administrators")

$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($subKey,
    [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,
    [System.Security.AccessControl.RegistryRights]::TakeOwnership)
$acl = $key.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Owner)
$acl.SetOwner($admin)
$key.SetAccessControl($acl)
$key.Close()

$key2 = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($subKey,
    [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,
    [System.Security.AccessControl.RegistryRights]::ChangePermissions)
$acl2 = $key2.GetAccessControl()
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($admin,
    [System.Security.AccessControl.RegistryRights]::FullControl,
    [System.Security.AccessControl.InheritanceFlags]::ContainerInherit,
    [System.Security.AccessControl.PropagationFlags]::None,
    [System.Security.AccessControl.AccessControlType]::Allow)
$acl2.SetAccessRule($rule)
$key2.SetAccessControl($acl2)
$key2.Close()

Set-Acl cmdlet 即使在管理员权限下也无法直接修改 TrustedInstaller 拥有的键,必须使用 .NET RegistryKey 类。

注册 CLSID

$clsidReg = "HKLM\SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}"

reg add "$clsidReg" /ve /t REG_SZ /d "CImeServerChs" /f
reg add "$clsidReg\LocalServer32" /ve /t REG_SZ /d "C:\Windows\System32\InputMethod\CHS\ChsIME.exe" /f

关于 InProcServer32:测试了系统中所有导出 DllGetClassObject 的相关 DLL(IMETIP.DLL、ChsPinyinDS.dll、ChsEM.dll、ChsIFEComp.dll、ChsProxyDS.dll、ServiceDS.dll、ChsAdvancedDS.dll),没有任何一个支持此 CLSID。仅使用 LocalServer32 即可正常工作。

注册 TIP 类别

$tipClsid = "{81d4e9c9-1d3b-41bc-9e6c-4b40bf79e35e}"
$tipReg = "HKLM\SOFTWARE\Microsoft\CTF\TIP\$tipClsid"

$categories = @(
    "{046B8C80-1647-40F7-9B21-B93B81AABC1B}",  # Display Attribute Provider
    "{13A016DF-560B-46CD-947A-4C3AF1E0E35D}",  # Immersive Support
    "{25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}",  # UI Element Enabled
    "{34745C63-B2F0-4784-8B67-5E12C8701A31}",  # Keyboard(此 build 的正确 GUID)
    "{364215D9-75BC-11D7-A6EF-00065B84435C}",  # Prop UI
    "{364215DA-75BC-11D7-A6EF-00065B84435C}",  # Prop UI 2
    "{49D2F9CE-1F5E-11D7-A6D3-00065B84435C}",  # Secure Mode
    "{49D2F9CF-1F5E-11D7-A6D3-00065B84435C}",  # TSF3
    "{74769EE9-4A66-4F9D-90D6-BF8B7C3EB461}",  # Extra
    "{CCF05DD7-4A87-11D7-A6E2-00065B84435C}",  # Extra
    "{3AF314A2-D79F-4B1B-9992-15086D339B05}"   # GIP(需设置 RuntimeClass)
)

foreach ($cat in $categories) {
    # Category\Category\{CAT}\{TIP}
    reg add "$tipReg\Category\Category\$cat\$tipClsid" /f
    # Category\Item\{TIP}\{CAT}
    reg add "$tipReg\Category\Item\$tipClsid\$cat" /f
    # 全局类别列表
    reg add "HKLM\SOFTWARE\Microsoft\CTF\Categories\Category\Item\$cat\$tipClsid" /f
}

# GIP 类别需要设置 RuntimeClass
reg add "$tipReg\Category\Category\{3AF314A2-D79F-4B1B-9992-15086D339B05}" `
    /v RuntimeClass /t REG_SZ /d "Windows.UI.Internal.Text.Core.GipFactory" /f

# Category\Item 设置 Description
reg add "$tipReg\Category\Item\$tipClsid" `
    /v Description /t REG_SZ /d "ChsIME.exe" /f

注册 LanguageProfile

$lpKey = "$tipReg\LanguageProfile\0x00000804\{FA550B04-5AD7-411F-A5AC-CA038EC515D7}"

reg add "$lpKey" /v Description /t REG_SZ /d "Microsoft Pinyin" /f
reg add "$lpKey" /v "Display Description" /t REG_EXPAND_SZ /d "@%SystemRoot%\SYSTEM32\input.dll,-5300" /f
reg add "$lpKey" /v IconFile /t REG_EXPAND_SZ /d "%SystemRoot%\SYSTEM32\InputMethod\Shared\ResourceDll.dll" /f
reg add "$lpKey" /v IconIndex /t REG_DWORD /d 0x1 /f
reg add "$lpKey" /v Enable /t REG_DWORD /d 0x1 /f
reg add "$lpKey" /v ProfileFlags /t REG_DWORD /d 0x2 /f

设置语言列表和默认输入法

# 确保语言列表包含微软拼音
$list = Get-WinUserLanguageList
# zh-Hans-CN 应包含 0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}
# 此标识符来自官方文档:
# https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-input-locales-for-windows-language-packs

# 设置默认输入法
Set-WinDefaultInputMethodOverride -InputTip "0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}"

替代方案:也可使用 DISM 命令设置输入区域(需离线镜像或管理员权限):

Dism /Online /Set-InputLocale:0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}

重启服务

Stop-Process -Name ctfmon -Force -ErrorAction SilentlyContinue
Stop-Process -Name ChsIME -Force -ErrorAction SilentlyContinue
Start-Sleep 2
Start-Process ctfmon

最终注册表状态

CLSID

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}
    (Default)    REG_SZ    CImeServerChs

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}\LocalServer32
    (Default)    REG_SZ    C:\Windows\System32\InputMethod\CHS\ChsIME.exe

TIP 类别

HKLM\SOFTWARE\Microsoft\CTF\TIP\{81d4e9c9-1d3b-41bc-9e6c-4b40bf79e35e}\Category\Category\
├── {046B8C80-1647-40F7-9B21-B93B81AABC1B}\{81d4e9c9-...}     # Display Attribute Provider
├── {13A016DF-560B-46CD-947A-4C3AF1E0E35D}\{81d4e9c9-...}     # Immersive Support
├── {25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}\{81d4e9c9-...}     # UI Element Enabled
├── {34745C63-B2F0-4784-8B67-5E12C8701A31}\{81d4e9c9-...}     # Keyboard
├── {364215D9-75BC-11D7-A6EF-00065B84435C}\{81d4e9c9-...}     # Prop UI
├── {364215DA-75BC-11D7-A6EF-00065B84435C}\{81d4e9c9-...}     # Prop UI 2
├── {3AF314A2-D79F-4B1B-9992-15086D339B05}                     # GIP
│   └── RuntimeClass = Windows.UI.Internal.Text.Core.GipFactory
│   └── {81d4e9c9-...}
├── {49D2F9CE-1F5E-11D7-A6D3-00065B84435C}\{81d4e9c9-...}     # Secure Mode
├── {49D2F9CF-1F5E-11D7-A6D3-00065B84435C}\{81d4e9c9-...}     # TSF3
├── {74769EE9-4A66-4F9D-90D6-BF8B7C3EB461}\{81d4e9c9-...}     # Extra
└── {CCF05DD7-4A87-11D7-A6E2-00065B84435C}\{81d4e9c9-...}     # Extra

LanguageProfile

HKLM\SOFTWARE\Microsoft\CTF\TIP\{81d4e9c9-...}\LanguageProfile\0x00000804\{FA550B04-5AD7-411F-A5AC-CA038EC515D7}
    Description         REG_SZ          Microsoft Pinyin
    Display Description REG_EXPAND_SZ  @%SystemRoot%\SYSTEM32\input.dll,-5300
    IconFile            REG_EXPAND_SZ  %SystemRoot%\SYSTEM32\InputMethod\Shared\ResourceDll.dll
    IconIndex           REG_DWORD      0x1
    Enable              REG_DWORD      0x1
    ProfileFlags        REG_DWORD      0x2

语言列表

zh-Hans-CN: 0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}
en-US:      0409:00000409

踩坑记录

键盘类别 GUID 必须匹配系统

官方文档 Predefined Category ValuesGUID_TFCAT_TIP_KEYBOARD{34745C63-B2F0-4784-8B85-9C39E1B59F3E},但 Windows 11 Build 26200 实际使用 {34745C63-B2F0-4784-8B67-5E12C8701A31}必须检查系统中其他正常工作的 TIP 使用哪个 GUID,不能盲目照搬文档。

GIP 框架是必需的

Windows 11 使用 GIP(Generic Input Processor)框架激活 TIP。仅注册传统 TSF 类别不够,必须添加 GIP 类别 {3AF314A2-D79F-4B1B-9992-15086D339B05} 并设置 RuntimeClass = Windows.UI.Internal.Text.Core.GipFactory

TrustedInstaller 权限处理

CLSID {81D4E9C9-...} 的注册表键由 TrustedInstaller 拥有,管理员默认只有 ReadKey 权限。需要:

  1. 通过 P/Invoke 启用 SeTakeOwnershipPrivilege
  2. 使用 .NET RegistryKey.OpenSubKeyTakeOwnership 权限打开
  3. 修改所有者后再授予 FullControl

Set-Acl cmdlet 即使在管理员权限下也无法直接修改 TrustedInstaller 拥有的键。

InProcServer32 非必需

繁体中文的 Microsoft Bopomofo TIP 同时有 InProcServer32(IMTCTIP.DLL)和 LocalServer32(ChtIME.exe),但简体中文的微软拼音仅使用 LocalServer32(ChsIME.exe)即可正常工作。系统中没有任何 DLL 支持微软拼音的 CLSID {81D4E9C9-...}

COM 激活缓存

在测试不同 DLL 作为 InProcServer32 时,COM 会缓存激活失败的结果。在同一进程中重试 Activator::CreateInstance 可能继续失败。需要从新进程测试 COM 激活。

Display Description 资源 ID

input.dll 资源 ID -5091 对应"微软拼音新体验",-5300 才对应"微软拼音"。需要通过 LoadStringW 实际加载验证,不能猜测。

参考模板:Microsoft Bopomofo

繁体中文的 Microsoft Bopomofo(TIP {B115690A-EA02-48D5-A231-E3578D2FDF80})是最佳的参考模板,其结构与微软拼音几乎一致:

  • CLSID 名称:CImeServerCht(对应 CImeServerChs
  • 同样的类别集合
  • 同样的 LanguageProfile 值结构
  • LocalServer32 指向 ChtIME.exe(对应 ChsIME.exe

参考文档

文档 链接 说明
Text Service Registration https://learn.microsoft.com/en-us/windows/win32/tsf/text-service-registration TSF TIP 注册的官方指南(COM API 方式)
Predefined Category Values https://learn.microsoft.com/en-us/windows/win32/tsf/predefined-category-values 预定义类别 GUID 列表(注意:与 Win11 实际值不一致)
ITfInputProcessorProfiles https://learn.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfinputprocessorprofiles TIP 注册管理接口
AddLanguageProfile https://learn.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-addlanguageprofile 添加语言配置文件方法
RegisterCategory https://learn.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcategorymgr-registercategory 注册类别方法
Default input profiles https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-input-locales-for-windows-language-packs 各语言的默认输入配置文件标识符
Set-WinUserLanguageList https://learn.microsoft.com/en-us/powershell/module/international/set-winuserlanguagelist PowerShell 语言列表管理 cmdlet

完整修复脚本

# 修复微软拼音输入法 TIP 注册
# 需以管理员身份运行

$tipClsid = "{81d4e9c9-1d3b-41bc-9e6c-4b40bf79e35e}"
$profileGuid = "{FA550B04-5AD7-411F-A5AC-CA038EC515D7}"
$clsidReg = "HKLM\SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}"
$tipReg = "HKLM\SOFTWARE\Microsoft\CTF\TIP\$tipClsid"

# === 1. 启用权限 ===
$privCode = @'
using System;
using System.Runtime.InteropServices;
public class Priv {
    [DllImport("advapi32.dll", SetLastError=true)]
    public static extern bool OpenProcessToken(IntPtr h, int acc, out IntPtr phtok);
    [DllImport("advapi32.dll", SetLastError=true)]
    public static extern bool LookupPrivilegeValue(string host, string name, out long pluid);
    [DllImport("advapi32.dll", SetLastError=true)]
    public static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TP newst, int len, IntPtr prev, IntPtr relen);
    [DllImport("kernel32.dll")]
    public static extern IntPtr GetCurrentProcess();
    [StructLayout(LayoutKind.Sequential, Pack=1)]
    public struct TP { public int Count; public long Luid; public int Attr; }
    public const int SE_PRIVILEGE_ENABLED = 2;
    public const int TOKEN_QUERY = 8;
    public const int TOKEN_ADJUST_PRIVILEGES = 32;
    public static bool Enable(string priv) {
        IntPtr tok;
        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, out tok)) return false;
        long luid;
        if (!LookupPrivilegeValue(null, priv, out luid)) return false;
        TP tp = new TP { Count = 1, Luid = luid, Attr = SE_PRIVILEGE_ENABLED };
        return AdjustTokenPrivileges(tok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
    }
}
'@
Add-Type -TypeDefinition $privCode
[Priv]::Enable("SeTakeOwnershipPrivilege")
[Priv]::Enable("SeRestorePrivilege")

# === 2. 获取 CLSID 键所有权 ===
$subKey = "SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}"
$admin = New-Object System.Security.Principal.NTAccount("Administrators")

$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($subKey,
    [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,
    [System.Security.AccessControl.RegistryRights]::TakeOwnership)
$acl = $key.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Owner)
$acl.SetOwner($admin)
$key.SetAccessControl($acl)
$key.Close()

$key2 = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($subKey,
    [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,
    [System.Security.AccessControl.RegistryRights]::ChangePermissions)
$acl2 = $key2.GetAccessControl()
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($admin,
    [System.Security.AccessControl.RegistryRights]::FullControl,
    [System.Security.AccessControl.InheritanceFlags]::ContainerInherit,
    [System.Security.AccessControl.PropagationFlags]::None,
    [System.Security.AccessControl.AccessControlType]::Allow)
$acl2.SetAccessRule($rule)
$key2.SetAccessControl($acl2)
$key2.Close()

# === 3. 注册 CLSID ===
reg add "$clsidReg" /ve /t REG_SZ /d "CImeServerChs" /f
reg add "$clsidReg\LocalServer32" /ve /t REG_SZ /d "C:\Windows\System32\InputMethod\CHS\ChsIME.exe" /f

# === 4. 注册 TIP 类别 ===
$categories = @(
    "{046B8C80-1647-40F7-9B21-B93B81AABC1B}",
    "{13A016DF-560B-46CD-947A-4C3AF1E0E35D}",
    "{25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}",
    "{34745C63-B2F0-4784-8B67-5E12C8701A31}",
    "{364215D9-75BC-11D7-A6EF-00065B84435C}",
    "{364215DA-75BC-11D7-A6EF-00065B84435C}",
    "{49D2F9CE-1F5E-11D7-A6D3-00065B84435C}",
    "{49D2F9CF-1F5E-11D7-A6D3-00065B84435C}",
    "{74769EE9-4A66-4F9D-90D6-BF8B7C3EB461}",
    "{CCF05DD7-4A87-11D7-A6E2-00065B84435C}",
    "{3AF314A2-D79F-4B1B-9992-15086D339B05}"
)

foreach ($cat in $categories) {
    reg add "$tipReg\Category\Category\$cat\$tipClsid" /f
    reg add "$tipReg\Category\Item\$tipClsid\$cat" /f
    reg add "HKLM\SOFTWARE\Microsoft\CTF\Categories\Category\Item\$cat\$tipClsid" /f
}

# GIP RuntimeClass
reg add "$tipReg\Category\Category\{3AF314A2-D79F-4B1B-9992-15086D339B05}" `
    /v RuntimeClass /t REG_SZ /d "Windows.UI.Internal.Text.Core.GipFactory" /f

# Category Item Description
reg add "$tipReg\Category\Item\$tipClsid" /v Description /t REG_SZ /d "ChsIME.exe" /f

# === 5. 注册 LanguageProfile ===
$lpKey = "$tipReg\LanguageProfile\0x00000804\$profileGuid"
reg add "$lpKey" /v Description /t REG_SZ /d "Microsoft Pinyin" /f
reg add "$lpKey" /v "Display Description" /t REG_EXPAND_SZ /d "@%SystemRoot%\SYSTEM32\input.dll,-5300" /f
reg add "$lpKey" /v IconFile /t REG_EXPAND_SZ /d "%SystemRoot%\SYSTEM32\InputMethod\Shared\ResourceDll.dll" /f
reg add "$lpKey" /v IconIndex /t REG_DWORD /d 0x1 /f
reg add "$lpKey" /v Enable /t REG_DWORD /d 0x1 /f
reg add "$lpKey" /v ProfileFlags /t REG_DWORD /d 0x2 /f

# === 6. 设置默认输入法 ===
Set-WinDefaultInputMethodOverride -InputTip "0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}"

# === 7. 重启 ctfmon ===
Stop-Process -Name ctfmon -Force -ErrorAction SilentlyContinue
Stop-Process -Name ChsIME -Force -ErrorAction SilentlyContinue
Start-Sleep 2
Start-Process ctfmon

Write-Output "Done! Press Win+Space to switch to Microsoft Pinyin."

验证方法

# 检查语言列表
Get-WinUserLanguageList

# 检查 TIP 注册
reg query "HKLM\SOFTWARE\Microsoft\CTF\TIP\{81d4e9c9-1d3b-41bc-9e6c-4b40bf79e35e}" /s

# 检查 CLSID 注册
reg query "HKLM\SOFTWARE\Classes\CLSID\{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}" /s

# COM 激活测试(需从新进程运行)
$type = [Type]::GetTypeFromCLSID([Guid]"81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E")
$obj = [Activator]::CreateInstance($type)
Start-Sleep 2
Get-Process -Name ChsIME -ErrorAction SilentlyContinue
posted @ 2026-08-09 15:22  undefined443  阅读(5)  评论(0)    收藏  举报