Current charset of the windows script host

落花浮王杯 提交于 2021-01-28 19:32:02

问题


I write script (js or vbs, not significant) with Windows Script Host that creating .bat file.

I want to convert ANSI string to OEM with ADODB.Stream

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.

How I may get the current ANSI(script) charset?


回答1:


The Windows codepage can be determined via WMI, by reading the CodeSet property of the Win32_OperatingSystem class.

There are several ways for reading properties of that class. In batch scripts you'd use the commandline executable wmic:

wmic os get codeset

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


来源:https://stackoverflow.com/questions/27868898/current-charset-of-the-windows-script-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!