Windows脚本主机的当前字符集 [英] Current charset of the windows script host

查看:69
本文介绍了Windows脚本主机的当前字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用创建.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆