Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change a Windows user's regional settings/date format?

I use a VB6/COM+ application which outputs date/time values based on the short date settings in the Control Panel, Regional Settings, for the user that runs it. The program that then parses that output has a configurable setting for the date format it expects, and presents in the UI.

e.g. If the regional setting for the user is set to mm/dd/yyyy, and it outputs 06/18/2009, the application expecting "18/06/2009" fails with "String was not recognized as a valid DateTime".

As we usually run this application as a service account, which we have not logged in as interactively to create a profile, we generally set the correct date format and then tick the "Apply all settings to the current user account and the default user profile" option.

I would like to be make the C# configuration utility I have written for this mess to be able to set the date format programmatically for a given user.

Edit I would like nothing more than to change the code, but do not have the ability to do so at this time.

I also know that what I am asking is a bad thing to do. With regards to "it should be the user's choice" - I am that user, as I create it explicitly for the task; I just want to set the date format by a scripted method, rather than having to do the clicking myself.

like image 596
crb Avatar asked Jun 18 '09 17:06

crb


1 Answers

This is specifically discouraged by Microsoft. Any solution you may come up with will be a filthy hack that will probably stop working soon.

Think of it this way: who are you to decide those settings? Don't you think that's the user's decision?

Back on topic: find an unambiguous format for the applications to communicate in, such as YYYYMMDD. The application that displays can then simply respect the actual user settings, as it should.

But, since you can't change it, just poke into the registry:

Current user:

HKEY_CURRENT_USER\Control Panel\International

Specific user:

HKEY_USERS\(user SID)\Control Panel\International

Default user:

HKEY_USERS\.DEFAULT\Control Panel\International

sShortDate is probably the value you want to change.

like image 82
Stu Avatar answered Sep 21 '22 17:09

Stu