Search code examples
windowsshellcultureinfoculturewindows-scripting

What are the valid country codes available for the windows 'net user' command?


I have a Windows script that creates a user using 'net user'. I need to ensure that this user is created with US-English countrycode even when run on a Japanese OS. The documentation here suggests there is a 3-digit code required for this but nowhere can I find an example or list of what the valid codes are. I've tried 840, 409 and 1033 - all give the error "An illegal country/region code has been supplied." Any ideas?

net user testUser testPwd123 /add /countrycode:840


Solution

  • The validation of the country code is actually implemented by NET USER command. The underlying NetUserSetInfo API will allow you to set whatever country code number you like. If you set the country code to a number which NET USER doesn't recognise, it displays the country as (null).

    The NetUserSetInfo API has separate country code and code page fields. You can set the country code using USER_INFO_1024 and the code page using USER_INFO_1025. However, the NET USER command appears to only know about the country code and offers no way to set or display the code page. Furthermore, if I create a new user and SSH to it, the user's code page setting appears to make no difference to the code page displayed by the CHCP command.

    The NET USER country codes actually derive from MS-DOS and OS/2. They are based on a subset of international dialling codes with some modifications. They ultimately date back to the COUNTRY= statement in MS-DOS CONFIG.SYS

    I doubt that Windows currently does anything with these codes. I think they are actually a left-over from the support of MS-DOS and OS/2 clients which was included in earlier versions of Windows. The NET command is a part of Windows which historically descends from IBM/Microsoft LAN Manager for MS-DOS and OS/2. The fact that the list of supported country codes is so restrictive is a sign of the fact that this is a disused historical vestige – if this setting was actually used for anything any more, there would be demand for adding a broader range of supported values.

    Here are the supported values (in Windows 10 version 2004, but I expect far older versions of Windows will produce the same results):

    Country Code Country
    000 System Default
    001 United States
    002 Canada (French)
    003 Latin America
    031 Netherlands
    032 Belgium
    033 France
    034 Spain
    039 Italy
    041 Switzerland
    044 United Kingdom
    045 Denmark
    046 Sweden
    047 Norway
    049 Germany
    061 Australia
    081 Japan
    082 Korea
    086 China (PRC)
    088 Taiwan
    099 Asia
    351 Portugal
    358 Finland
    785 Arabic
    972 Hebrew

    Here is a Windows batch file I used to produce the above list:

    @echo off
    setlocal enableextensions enabledelayedexpansion
    rem Make sure we are using Windows commands not Cygwin/etc if you happen to have Cygwin first in PATH
    PATH %systemroot%\system32
    NET USER DELETEME myCmplxPwd1! /ADD 1>NUL: 2>NUL:
    echo. >NETUSER.TMP
    FOR /L %%i IN (0,1,999) DO (
            NET USER DELETEME /COUNTRYCODE:%%i 1>NUL: 2>NUL:
            NET USER DELETEME | findstr Country >> NETUSER.TMP
    )
    net user deleteme /delete 1>NUL: 2>NUL:
    type netuser.tmp | sort /unique
    del netuser.tmp