1

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?

Ezhik
  • 876
  • 6
  • 23
  • Why do you need that? Where does the "ANSI" string come from? – Ansgar Wiechers Jan 10 '15 at 10:23
  • This is scenario for automatic deployment. For example in Russian environment Windows would have OEM charset "CP866" and ANSI charset "windows-1251". windows-1251 is charset of script itself. http://en.wikipedia.org/wiki/Windows_code_page Also part of code is auto-generated with UTF8 strings. I need explicit information about charsets. – Ezhik Jan 10 '15 at 19:13
  • 1
    You can check the code set via [WMI](http://msdn.microsoft.com/en-us/library/aa394239%28v=vs.85%29.aspx), but again: why? What do you want to do with this information? – Ansgar Wiechers Jan 10 '15 at 20:47
  • Simplest scenario: store data with customer strings and field with charset value. This will allow serialize/deserialize data and generate new data for different endpoints with different charsets. – Ezhik Jan 11 '15 at 06:08

1 Answers1

2

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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328