Windows脚本主机的当前字符集 [英] Current charset of the windows script host
问题描述
我使用创建.bat文件的Windows脚本宿主编写脚本(js或vbs,不重要).
I write script (js or vbs, not significant) with Windows Script Host that creating .bat file.
我想使用ADODB.Stream将ANSI字符串转换为OEM
I want to convert ANSI string to OEM with ADODB.Stream
我可能会使用Split(CreateObject("WScript.Shell").Exec("cmd /c chcp").StdOut.ReadAll, ":")(1)
获得当前的OEM代码页,然后使用
I may get current OEM code page with Split(CreateObject("WScript.Shell").Exec("cmd /c chcp").StdOut.ReadAll, ":")(1)
and then convent it to charset with http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx.
如何获取当前的ANSI(脚本)字符集?
How I may get the current ANSI(script) charset?
推荐答案
The Windows codepage can be determined via WMI, by reading the CodeSet
property of the Win32_OperatingSystem
class.
有几种方法可以读取该类的属性.在批处理脚本中,您将使用命令行可执行文件wmic
:
There are several ways for reading properties of that class. In batch scripts you'd use the commandline executable wmic
:
wmic os get codeset
在VBScript中,您可以脱壳并使用相同的命令,但是随后您必须解析文本输出以获得实际值.最好这样做:
In VBScript you could shell out and use the same command, but then you'd have to parse text output to get the actual value. It's better to do it this way:
Set wmi = GetObject("winmgmts://./root/cimv2")
For Each os In wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem")
cs = os.CodeSet
Next
WScript.Echo cs
这篇关于Windows脚本主机的当前字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!