What encoding to get Å Ä Ö to work
Edit: I was wrong ;)cmd.exe
does accept UTF-8 but you need to be sure to save it without the BOM
at the beginning of the file.
Here is a second test. You can use chcp 65001
at the beginning of your batch-file.
A batch file can not be of type UTF-8. It needs to be ASCII. Cmd.exe
just doesn't accept another format. I did a small test and you can use your characters but it needs some work.
Make a file test.bat
with echo Å Ä Ö
. Save it with format ANSI/ASCII
. Open a cmd.exe
and make sure your cmd.exe
uses Lucida Console
(to display the Unicode characters).
When you type the file it will show characters as the old DOS-characters. You can see a translation chart here.
When you switch to a "Windows Ansi"-code page (i.e. West European Latin) with chcp 1252
the characters are displayed correctly. If they also get transferred to their respective utilities depends on that utility.
But why are you creating a batch-file for this? Can't you just code it in VB.net?
Edit 2#:
This is how you set Lucida Console
in cmd.exe
:
The BOM
are 3 characters at the beginning of a UTF-8 file. (\xEF\xBB\xBF
).
In VB.net you would create a file without a BOM
like this:
Dim utf8WithoutBom As New System.Text.UTF8Encoding(False)
'^^^^^'
Using sink As New StreamWriter("Foobar.txt", False, utf8WithoutBom)
sink.WriteLine("...")
End Using
The thing that fixed this for me was to save the file as UTF-8 without BOM and using this code
@echo off
chcp 65001
net user Linus /add
net localgroup Administratörer Test/add
The thing I didn't use before was @echo off so that and using chcp 65001 is what fixed it! Thanx too Rik for all the help :)