Windows CJK 用户名编码问题与修复
问题现象
在 Windows 上使用中文(CJK)用户名安装 OpenClaw 后,网关服务无法启动,弹窗提示:
找不到 C:\Users<用户名>.openclaw\gateway.vbs
根因分析
文件编码不匹配
OpenClaw 安装脚本生成 gateway.vbs 和 gateway.cmd 时使用 UTF-8 编码,但:
文件 执行器 支持的编码 不支持
gateway.vbs Windows Script Host (wscript.exe) ANSI (GBK) / UTF-16 LE BOM ❌ UTF-8
gateway.cmd cmd.exe ANSI (GBK, 代码页 936) ❌ UTF-8
编码转换过程
以三字节中文字符为例:
UTF-8 字节: e8 xx xx e6 xx xx (6 字节)
GBK 解读: 乱码 (路径失效)
UTF-16 LE: 正确的 Unicode 码点 (正确识别)
WSH 按 GBK 解码 UTF-8 字节后,路径变成乱码,自然找不到目标文件。
修复方案
手动修复
gateway.vbs -> UTF-16 LE BOM (WSH 支持)
[System.IO.File]::WriteAllText(
“KaTeX parse error: Undefined control sequence: \gateway at position 26: …OFILE\.openclaw\̲g̲a̲t̲e̲w̲a̲y̲.vbs", [Sys…env:USERPROFILE.openclaw\gateway.vbs”),
[System.Text.Encoding]::Unicode
)
gateway.cmd -> GBK (cmd.exe 默认编码)
[System.IO.File]::WriteAllText(
“KaTeX parse error: Undefined control sequence: \gateway at position 26: …OFILE\.openclaw\̲g̲a̲t̲e̲w̲a̲y̲.cmd", [Sys…env:USERPROFILE.openclaw\gateway.cmd”),
[System.Text.Encoding]::GetEncoding(‘gbk’)
)
重启网关
openclaw gateway restart
一键脚本
已创建修复脚本 ~/.openclaw/fix-encoding.ps1,执行:
powershell -File ~/.openclaw/fix-encoding.ps1 && openclaw gateway restart
什么时候需要修复
场景 是否需要修复
openclaw gateway install --force ✅ 会覆盖文件
iwr -useb https://openclaw.ai/install.ps1 | iex ✅ 安装过程会覆盖
openclaw gateway restart ❌ 不会覆盖文件
openclaw gateway start/stop ❌ 不会覆盖文件
OpenClaw 版本升级 ✅ 大概率会覆盖
涉及文件说明
文件 作用
~/.openclaw/gateway.vbs VBS 启动器,由计划任务调用,内部执行 gateway.cmd
~/.openclaw/gateway.cmd 实际启动 Node.js 网关进程的批处理脚本
~/.openclaw/fix-encoding.ps1 编码修复脚本
gateway.vbs 内容示例
’ OpenClaw Gateway (v2026.7.1)
CreateObject(“WScript.Shell”).Run “”“C:\Users<用户名>.openclaw\gateway.cmd”“”, 0, False
gateway.cmd 内容示例
@echo off
rem OpenClaw Gateway (v2026.7.1)
set “TMPDIR=C:\Users<用户名>\AppData\Local\Temp”
set “OPENCLAW_GATEWAY_PORT=18789”
…
<node路径> <openclaw路径>\dist\index.js gateway --port 18789
排查命令
检查文件编码
file ~/.openclaw/gateway.vbs
file ~/.openclaw/gateway.cmd
检查计划任务状态
powershell -Command “Get-ScheduledTask -TaskName ‘OpenClaw Gateway’ | Format-List State, Actions”
检查网关运行状态
openclaw gateway status --json
相关链接
● 上游 Issue: https://github.com/openclaw/openclaw/issues/107416
更多推荐


所有评论(0)