Net Functions

Net Functions

I want to programatically add a user to the Administrators group. The API NetLocalGroupAddMembers() works when adding my user to English Windows NT, but will not add the user to Spanish Windows NT because the Administrators group name is in Spanish–the API takes the group name as parameter. How can I generically add my user to the Administrators group without necessitating producing localised versions of my application?

You can use the API call GetUserDefaultLCID to get the user-default location identifier. For example, 0409 is the LCID for US/English, 080a is Spanish (Mexico), etc. (look up “LCID Reference” in MSDN, searching titles only). You can then make a resource file with the name of the administrator group for each language that you want to support. After looking up the LCID for the current user, you can then use that as a pointer to get the correct characters from the resource file for “Administrator” in that language. If you have a number of language-specific words you need to use for the API calls, then you might want to create offsets of each supported language to form ranges of values in the resource file. So, for example, the characters that spell “Administrator” might be at the lookup value + 0, the value for “User” might be at lookup value + 1, etc.


Share the Post: