A customer had a program that automated a workflow, and one of the steps was to run a console program that came with Windows, and that console program printed a confirmation prompt “Are you sure (Y/N)?“. They wanted to programmatically say Yes, but since the customer had employees around the world, they couldn’t hard code the letter Y into their program. (For example, in German, it would be J/N instead of Y/N.) They also realized that the characters for affirmative and negative replies were stored in resources in the executable, so instead of having a big table of affirmative and negative replies for each language, they could load those strings from the executable and use them to answer the questions. They wanted to know if this is acceptable and supported.
No, it’s neither supported nor acceptable.
Unless documented otherwise, resource strings are considered implementation details of the program. Absent any promises to the contrary, Windows reserves the right to change any resource string, or to move them to another location.
Indeed, one of my colleagues gave an example of how this actually happened in recent memory.
The translation team received a bug report that one of the programs had mistranslated “Y/N”. They fixed the translation, but since the fix was going out in a servicing release, they couldn’t change the existing incorrect string because that would invalidate Language Interface Packs. Instead, they had to abandon the old string and create a new one. All the languages would then translate the new string to Yes and No, which would just be copied from the existing translation, except for the language that had an incorrect translation, in which case it would be re-translated, but correctly this time. The program would switch to using the new better-translated string for determining whether the user responded in the affirmative or negative, and the old string would become orphaned, waiting to be cleaned up at the next major release.
If the customer had been extracting strings directly from the binary, they would continue extracting the yes/no string from its old location, even though the program was using the string in its new location.
The customer should provide appropriate affirmative and negative answers, or even better, avoid having to answer the question at all. I forget which program it was, but maybe it had a /F or /Q option to suppress the confirmation prompt. Even better would to avoid the console program at all and access the underlying functionality in a programmatic way. (For example, use Copy-Item or CopyFile instead of xcopy.exe; or use Set-ItemProperty or RegSetValueEx instead of reg.exe.
I’m using number of strings from COMDLG32.DLL stringtables and if you change their ID (which remained the same since XP), I’ll just update my program.
Do your customers understand that “Jan’s program may stop working at any update, please contact Jan to get a new version”? Can we send the app compat bugs to you?
(And if the customer has a mix of systems on different update schedules, I guess you need to make the program detect which OS version it is running on, so it can get the string from the right place.)
I tried to think of how this could come to be that they would be invoking a command line program.
I only came up with three good answers: all of which you _really_ don't want them looking for other solutions.
1) dism.exe
2) chkdsk.exe
3) format.com (or is it format.exe now?)
format.com was the worst in this regard; as it does have an option to suppress the prompt, this results in a lot worse runtime. /Q and /U were not miscable in all cases.
I've used a similar technique with other programs; but I found it expedient to ship the binary myself to (among...
Perhaps the customer could temporarily change the code page before run the console program?
chcp 65001