Windows 11 no longer honors SetFileApisToOEM in child CMD.EXE command line

Uwe Baemayr 41 Reputation points
2022-08-17T15:39:15.21+00:00

We have a module that uses CreateProcess() to invoke CMD.EXE and that can pass a MBCS command line to CMD.EXE that can contain 8-bit characters.

Before Windows 11, it appears that a CMD.EXE created in this way used the SetFileApisToANSI() and SetFileApisToOEM() setting to determine whether the command line should be treated as containing OEM or ANSI characters. Specifically, if SetFileApisToOEM() is in effect, a command line containing OEM characters was converted to ANSI before execution.

For example, I have linked a program that issues these two C command lines in a program that uses CreateProcess() to invoke CMD.EXE:

const char * p_ans = "C:\\WINDOWS\\SYSTEM32\\CMD.exe /c mkdir DIR_FileApiANS_\x9c";    // OEM £ character saved with ANSI file API  
const char * p_oem = "C:\\WINDOWS\\SYSTEM32\\CMD.exe /c mkdir DIR_FileApiOEM_\x9c";    // OEM £ character saved with OEM file API  

SetFileApisToOEM();  
ExecCmd(p_oem);  
 
SetFileApisToANSI();  
ExecCmd(p_ans);  

ExecCmd() uses CreateProcess() to invoke CMD.EXE.

With this in effect, on Windows 10:

SetFileApisToANSI: 232101-image.png
SetFileApisToOEM: 232005-image.png

On Windows 11, same program:

SetFileApisToANSI: 232039-image.png
SetFileApisToOEM: 232040-image.png

I can't attach a ZIP file, but here is a simple program with a Visual Studio project: https://www.dropbox.com/s/d21ewb7r09jdnr1/CmdWithFileApiAnsiOem.zip?dl=0

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,606 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,166 questions
{count} vote

4 answers

Sort by: Most helpful
  1. Uwe Baemayr 41 Reputation points
    2022-09-10T03:14:36.37+00:00

    Just to confirm: I did raise a case with technical support, and the problem reported here was reproduced. I also created a test case for what I now believe is the root of the problem: SetFileApisToOEM() simply does not work on Windows 11.

    The case number is 2208250050001982, if that's helpful to anyone.

    I'm currently in communication with a senior escalation engineer who has reproduced both the original CMD.EXE and the SetFileApisToOEM() problems using the test cases. I'm posting here mostly to make this problem come up in searches, just in case someone else encounters the same issue.

    1 person found this answer helpful.
    0 comments No comments

  2. Reza-Ameri 16,831 Reputation points
    2022-08-18T16:46:50.837+00:00

    In case you are using Visual Studio to develop this code, you may report this as a problem to the Visual Studio team and make sure specify this used to work in Windows 10 but not Windows 11.
    Have a look at:
    https://learn.microsoft.com/en-us/visualstudio/ide/how-to-report-a-problem-with-visual-studio?view=vs-2022


  3. Xiaopo Yang - MSFT 11,496 Reputation points Microsoft Vendor
    2022-08-25T08:29:19.813+00:00

    As this issue is complex, please open an incident via 'Contact us' tab at link below so that our engineer can work with you closely: https://developer.microsoft.com/en-us/windows/support/ and Please choose the 'Technical Support - Coding/Debugging' for Windows SDK for this issue. In-addition, if the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged. It‘s helpful to mention the number 2208180040002398 in the submitted incident. Finally, Please give the incident link back and we can trace the progress accordingly. Thank you.

    0 comments No comments

  4. Uwe Baemayr 41 Reputation points
    2022-11-22T15:52:44.663+00:00

    Microsoft has approved a fix for Windows 11 21H2 and almost certainly for 22H2 (still being investigated).

    No ETA yet, but this looks promising!

    0 comments No comments