vbs objShell.Exec 中文乱码
时间: 2023-10-14 09:04:34 浏览: 50
你好!对于 vbs 中使用 objShell.Exec 执行命令时出现中文乱码的问题,可以尝试下面几种解决方法:
1. 使用 chcp 命令设置命令行编码为 UTF-8:
```
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /c chcp 65001 & your_command", 0, True
```
在 your_command 处替换为你要执行的命令。
2. 使用 cmd.exe /u 参数执行命令,该参数表示使用 Unicode 编码:
```
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd.exe /u /c your_command", 0, True
```
在 your_command 处替换为你要执行的命令。
3. 使用 ADODB.Stream 对象读取命令输出并转换为 UTF-8 编码:
```
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec("your_command")
Set objStdOut = objExec.StdOut
Set objStream = CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 2 ' 文本类型
objStream.Charset = "UTF-8"
objStream.LoadFromStream objStdOut
output = objStream.ReadText
WScript.Echo output
```
在 your_command 处替换为你要执行的命令。
这些方法可以尝试解决 vbs 中使用 objShell.Exec 执行命令时出现中文乱码的问题。希望能帮到你!如果还有其他问题,请继续提问。