A nearly identical question was asked before. A good explanation of code pages was given in the reply, but it did not answer the question in my mind: What controls the code page used when cmd.exe is started? On my system, it gets changed somehow. In the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage, there is an item OEMCP that is set to 437. This seems to be the CP used by cmd.exe (as shown by chcp) after a fresh reboot, but something changes it later and it becomes 1252 in new cmd.exe windows. If I change it with chcp to 437, that only affects the current cmd.exe. When I exit and restart cmd.exe, chcp shows 1252 in the new window. What controls the default CP used when cmd.exe is started? How does it get changed from the value in the registry? How do I keep it from getting changed and/or change it back to 437 for new command windows?
The default code page in cmd.exe on my Windows syxtem is 437, which is the default OEM code page for most PC hardware sold in the United States (US) and Western Europe from what I've read. You can change this default by adding a string entry named AutoRun under one or both of the keys:
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
and
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor
in the Windows registry, as documented on this MS Windows Server 2003 support page. It describes how you can add a REG_SZstring entry named AutoRun under one or both of these keys with a value containing commands you want run automatically when cmd.exe starts up.
For example, to make code page 1252 the default, create a new string value named AutoRun after navigating to one of these keys in the regedit.exe utility program and then set its value to the command chcp 1252 afterwards.
Although the MS article only indicates it applies to Windows Server 2003, the technique also worked on the Win XP system I tested it on, so will probably also work with Vista & Win 7.
If Win+R and running cmd.exe /D fixes it then the problem is in the cmd autorun value...
Related
I have spent a very long time researching this. Most of the solutions were posted PRIOR to April 2018, and involved working your way through the "settings" to get to "Choose default Apps by file type".
Choose default Apps by file type
In previous attempts to assign an app to ".rex" I managed to assign it to Notepad. (At that time, I could not find any way to find an ".exe" on my C: drive.)
So as you can see, if you click on Notepad next to the .rex extension, the only option is to go to the "App store".
And as expected, if you click on App store, nothing is found...
App store - no app's found.
So from what I've read in multiple forums, PRIOR to April 2018, Windows 10 still had a way to "browse your hard drive" to find an ".exe". (Just like in older Windows versions.) After some update in April 2018, that capability no longer exists.
In the POST April 2018, has anyone found a way to assign a file extension to an ".exe" on the hard drive???
I think this question would be more suitable for SuperUser (well, unless you want to do it via a program :) ).
Anyway, here's a way of doing things from console (Cmd). I've tried it 1 or 2 years ago, I just tried it now, so it works regardless of Win (10) version.
Start the process from scratch:
Open a Command Prompt window. Create a new file that the OS doesn't know anything about. I chose the extension .zzz:
e:\Work\Dev\StackOverflow\q052008516>ver
Microsoft Windows [Version 10.0.17134.228]
e:\Work\Dev\StackOverflow\q052008516>dir /b
e:\Work\Dev\StackOverflow\q052008516>:: Create a dummy .zzz file
e:\Work\Dev\StackOverflow\q052008516>echo Some dummy text>file.zzz
e:\Work\Dev\StackOverflow\q052008516>dir /b
file.zzz
Try opening the file (DblClick) from a file browser (it's not relevant, but I use Total Commander), or by typing its name in Cmd. That will yield the dreaded dialog:
Create a new file type and associate our extension with it. [MS.Learn]: assoc utility is used to do the job. First, check if such association doesn't already exist:
e:\Work\Dev\StackOverflow\q052008516>:: No output means no association
e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".zzz"
e:\Work\Dev\StackOverflow\q052008516>:: Same command for a different extension
e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".txt"
.dic=txtfile
.exc=txtfile
.log=txtfile
.scp=txtfile
.txt=txtfile
.wtx=txtfile
e:\Work\Dev\StackOverflow\q052008516>:: Create a new FileType (ZZZFile) and associate our extension with it
e:\Work\Dev\StackOverflow\q052008516>assoc .zzz=ZZZFile
.zzz=ZZZFile
e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".zzz"
.zzz=ZZZFile
No change when trying to open the file.
Associate the file type (ZZZFile, from previous step) with a command. Use the [MS.Learn]: ftype tool for the task. Again, check if the file type is not already associated (this only makes sense if the file type existed before previous step):
e:\Work\Dev\StackOverflow\q052008516>:: As usual, no output means no association
e:\Work\Dev\StackOverflow\q052008516>ftype | findstr ZZZFile
e:\Work\Dev\StackOverflow\q052008516>:: Same thing for txtfile
e:\Work\Dev\StackOverflow\q052008516>ftype | findstr txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
e:\Work\Dev\StackOverflow\q052008516>:: Associate ZZZFile with notepad
e:\Work\Dev\StackOverflow\q052008516>ftype ZZZFile=%SystemRoot%\system32\notepad.exe %1
ZZZFile=C:\WINDOWS\system32\notepad.exe %1
e:\Work\Dev\StackOverflow\q052008516>ftype | findstr ZZZFile
ZZZFile=C:\WINDOWS\system32\notepad.exe %1
Try opening the file again (from Cmd), and voilà:
Summary:
In order to open with Notepad files having .zzz extension, there are only 2 commands that need to be remembered from this whole (and pretty long) answer:
assoc .zzz=ZZZFile
ftype ZZZFile=%SystemRoot%\system32\notepad.exe %1
Notes:
My user has (super) administrative privileges, but I guess they shouldn't impact differently depending where the action is performed from (Cmd or UI (if possible)), in other words users that don't have the required privileges, won't be able to do it, no matter what they would try
Apparently, there is a (pretty dark) nebula on this topic, that my knowledge wasn't yet able to "decipher". In my example, I constantly compare the .zzz results to .txt. Yet a big surprise: Notepad++ and not Notepad is used to open txtfile (.txt only), in spite of the above output
Update #0
I did a little more digging on the .txt mystery. Facts:
FType shows Notepad as opening program
It is actually opened by Notepad++ (in Cmd and PS)
In Choose default apps by file type, Notepad++ is shown
So apparently, it's more than meets the eye (over the years, I got used to MS's way of doing things which in some cases seems to be (but maybe it's me who didn't have all the pieces) illogical).
I've also found out many resources like:
[MS.Technet.Blogs]: Windows 10 – How to configure file associations for IT Pros? which mentions the command:
dism /online /export-defaultappassociations:"file.txt"
[XDADevelopers]: Programatically set default file associations which mentions the reg keys:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${EXT}
HKCR\${EXT}
I couldn't find anywhere a clear algorithm of how an executable is chosen to run a file with a certain extension. I can think that the 2 keys above are queried, but I'm 100% sure there's more. Not to mention that I've ran into an even stranger problem (for a regular user on my Win 10), for .py files:
FType (and Assoc) reported everything as above
In Choose default apps by file type, Python was shown (just like in my Super Admin user's case)
Attempting to run the file from Cmd, yielded the dialog at the beginning
It worked from PS
Sadly, I selected Python from the dialog, before taking a look at the registry keys (and now it works), so I can't do any more debugging (and also, switching users is annoying).
Might be related:
[SuperUser]: Windows 10 won't let me set default apps for file extensions
[SuperUser]: Can't change Windows 10 default file type association
[SuperUser]: SSMS wont give up file associations
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
A long time ago I wanted to change the default codepage (CP) of windows console to UTF-8 (to view japanese characters). I can't remember the commands I used, but anyway I eventually managed to be able to view the characters on the cmd.exe. After a short time though, I noticed any programs using the cmd.exe would be in the Japanese codepage 932 by default and OEMCP was set to 932. After noticing this I checked the System Locale and changed it to English (United States). After doing this it was expected that OEMCP would have changed to 437, which it had and which also should have meant the default CP of cmd.exe was now 437. However even after the OEMCP had been changed to 437 the default CP of cmd.exe was still 932.
So how can I change the default CP back to 437? What is causing it to still be CP 932 by default? I have completely removed the Japanese Language from my PC to make sure it wasn't causing the issue, and many people have told me to use an autorun file or change the OEMCP to use CP 437, however OEMCP is already set as 437 and I do not want to use an autorun file for CP 437, I simply want it to be the default as it used to be.
I have also been told that there could be a script that's auto-running each time the cmd.exe is opened, but I have no idea how to track that or how to remove it.
Updates:
The issue is with cmd.exe using CP 932
powershell.exe and netsh.exe are both already using CP 437
The default configuration for console windows is stored in the registry key "HKCU\Console". Most of the properties in this key are configurable in the GUI using the console's Alt+Space [D]efaults dialog.
When a process allocates a new console, some of these defaults are directly overridden by the process STARTUPINFO. This includes the window position and size and the screen buffer size and fill attribute (i.e. text and background colors). The process startup information also includes an initial window title, which, if not set by the parent process, defaults to the fully-qualified path of the application executable. If the application is launched using a shell shortcut (i.e. LNK file), the title will be the path to the shortcut file instead of the executable, and the flag STARTF_TITLEISLINKNAME will be set.
The console uses the initial window title to load additional properties that customize the window. If the STARTF_TITLEISLINKNAME flag is set, it loads these additional properties from the LNK shortcut file that launched the application. Otherwise it looks for the normalized title as a subkey in the registry. To normalize the title, backslashes are replaced with underscore, and the Windows directory is replaced by "%SystemRoot%". For example, if the initial window title is "Spam\Eggs", it looks for settings under "HKCU\Console\Spam_Eggs". These properties are configurable in the GUI using the console's Alt+Space [P]roperties dialog.
One of the properties that can be set is a DWORD value named "CodePage". This is the initial legacy codepage for both input and output. (I say "legacy" because the console has a Unicode API that should always be preferred.) If it's not set, the console defaults to the OEM codepage (e.g. 850 in Western Europe or 437 in the U.S.). A LNK shortcut can also set a custom codepage in its ConsoleFEDataBlock, but it's not possible to modify this using the GUI, or even using the IShellLink COM interface.
For example, if cmd.exe is run directly from the Win+R run dialog instead of using a shortcut, it uses the default window title "C:\Windows\System32\cmd.exe". The console in turn, after loading its defaults from "HKCU\Console", looks for additional configuration in the subkey "HKCU\Console\%SystemRoot%_System32_cmd.exe". A "CodePage" value set there will override the console's default OEM codepage.
Unfortunately, if we want to change the initial codepage for all console applications, we'll be disappointed that setting it in "HKCU\Console" doesn't work. Due to a bug in the console (currently implemented by conhostv2.dll, which is hosted in conhost.exe), if we set a default "CodePage" value in "HKCU\Console", the console only briefly sets this value while loading and then resets itself to OEM.
Some time ago I had to change my system locale from Czech (default) to Japanese because I needed to run some Japanese programs that would otherwise crash.
The problem is, after switching back to Czech, my command prompt would launch with the Shift-JIS encoding whenever I opened it from the Win+R dialog (which is my preferred way of launching cmd). It would also draw characters in a strange bloated font. The problem persists even after uninstalling Japanese from my system altogether.
If I open cmd any other way (Start menu, Right-click Start -> Command Prompt, cmd.exe...), everything works correctly. All settings that I could think of are set to Czech:
System locale
Language for non-Unicode programs
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage (OEMCP value)
Another thing is that Regedit always opens on HKEY_CLASSES_ROOT\MIME\Database\Codepage, though I don't know if that's related to the problem.
I'm running Windows 10, after the free upgrade from 8.1 and 7. Picture shows the different cmd windows.
http://i.imgur.com/jyyhAOA.png
Settings are stored a number of places. Look here for a codepage value and delete it.
HKCU\Console\%SystemRoot%_system32_cmd.exe\
Overview:
I just have a quick question about the ability to remap keys for a single user in in the registry:
Resources used:
ASCII table used:
http://www.csee.umbc.edu/portal/help/theory/ascii.txt
https://superuser.com/questions/694465/remapping-a-keyboard-key-in-windows-8-1
Which pointed me towards: http://www.howtogeek.com/howto/windows-vista/disable-caps-lock-key-in-windows-vista/
Attempt:
That tutorial talked about making remapping keys at the machine level via:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout
So I thought to myself what the hell I would just try the same thing under: HKEY_CURRENT_USER\SYSTEM\CurrentControlSet\Control\Keyboard Layout
Unfortunately and somewhat expected it did not work:
reg add "HKEY_CURRENT_USER\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map" /t REG_BINARY /f /d 00000000000000000400000012005b005b00A200A200120000000000
^^^ This was supposed to switch: ^^^
the recognized windows key to the control key
the recognized alt key to the windows key
the recognized control key to the alt key
I even killed explorer.exe via power-shell:
taskkill.exe -im explorer.exe /f | Out-Null; start explorer.exe
Questions:
Is what I am trying to to even possible for a single user?
If it is how would I accomplish this without third party software?
That registry key is used by the keyboard driver. It reads it when it starts up. So killing Explorer has no effect, you'll have to reboot to make changes effective. Use shutdown.exe -r. Restarting the driver without a reboot is not possible.
Do beware that hacking this key is fairly dangerous, you can lose control over the machine when you make a mistake. I recommend KeyTweak, it has let me put the Ctrl key where it belongs for the past 10 years.
If it was to work, it would hypothetically have been in the HKEY_CURRENT_USER\Keyboard Layout key in the Registry. However, in the section "Scan code mapper for keyboards" in "Keyboard and mouse class drivers", it is noted:
"The mappings stored in the registry work at system level and apply to all users. These mappings cannot be set to work differently depending on the current user."
so it seems impossible to do mapping this way per-user. (It is the keyboard driver that reads this setting and does the translation, not the session manager).
For people finding this from an Internet search.
Microsoft PowerToys includes a tool for remapping keys for a user.
Probably safer than directly editing the registry.
https://github.com/microsoft/PowerToys
My Windows cmd CodePage is now under 65001.
Since I was doing some Android stuff and need to use console log, but forget how changing it now.
When using chcp 437 to change the CodePage back, it works. But if I start a new cmd window, it goes back.
How to do the chcp thing to make it pernament?
In the 1809 build of Windows 10 I've managed to permanently solve this by going to the system's Language settings, selecting Administrative language settings, clicking Change system locale... and checking the Beta: Use Unicode UTF-8 for worldwide language support box and then restarting my pc.
This way it applies to all applications, even those ones that I don't start from a command prompt!
(Which was necessary for me, since I was trying to edit Agda code from Atom.)
Here I found a better solution:
Start -> Run -> regedit
Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
Add new String Value named: Autorun
Change the value to 'chcp 437'
Create a start up batch file that includes all the commands you want.
Then edit the registry to point to your start up file.
http://technet.microsoft.com/en-us/library/cc779439%28WS.10%29.aspx
c:\startup.cmd
#echo off
chcp 437
HKLM\SOFTWARE\Microsoft\Command Processor
AUTORUN="C:\startup.cmd"
Command prompt code page always change back to the default 437 if you just use chcp 850 in cmd to change the active language code (850 = Multilingual (Latin I)).
My system default language is set to English (437) although I'm Brazilian (language code 850).
Once I need to show some special characters such as ã, õ, ç, I found that at Windows 10, under All Settings > Time & Language > Region & Language there is (at the top right corner) a link for Related settings - Additional date, time & regional settings. From there you'll be redirected to Control Panel\Clock, Language, and Region. Click again on Region > Change Location and at the window Region, at the tab Administrative, change the Language for non-Unicode programs by clicking the button Change system locale and choosing some other that uses the code you need (In my case, Portuguese (Brazil) = code 850). Restart Windows and check if your command prompt is now set to the new language code (type chcp in cmd). For me, it solved the problem.
There is also a Latin (Word) option on the list that I suppose is also code 850.
Setting the default CMD/shell Codepage can be neatly done using the following command:
REG ADD HKCU\Console\%SystemRoot^%_system32_cmd.exe /v CodePage /t REG_DWORD /d 437
This will make the codepage 437 your default, but ONLY in the cmd/shell, meaning the rest of the OS is safe and the boot environment ist untouched.
Instead of always changing the codepage whenever the cmd opens, the cmd will open in the specified codepage from start.
If you wish to edit it manually using regedit.exe, beware that you have to set the codepage value in 'decimal' (use the radio-buttons for selecting decimal or hex input).
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage
You can edit code page value permanently by editing OEMCP key value in windows in above reg key value
Warning: Don't do it, it will make your system unable to boot. See related.