How to change regional user settings / Windows date format?

I use the VB6 / COM + application, which displays the date / time values ​​based on the short date settings on the control panel, regional settings, for the user who runs it. The program, which then analyzes this output, has a custom parameter for the date format that it expects and presents in the user interface.

eg. If the locale for the user is set to mm / dd / yyyy and it issues 06/18/2009, the application expecting "06/18/2009" fails with "String was not recognized as a valid DateTime".

Since we usually run this application as a service account that we did not enter interactively to create a profile, we usually set the correct date format and then check “Apply all settings to the current user account and default user profile”.

I would like to make the C # configuration utility that I wrote for this mess in order to be able to set the date format programmatically for a given user.

Edit I would only like to change the code, but I have no way to do this at this time.

I also know that what I ask is bad. As for “this should be a user choice” - I am this user, since I create it explicitly for the task; I just want to set the date format using a script, instead of clicking on myself.

+3
source share
3 answers

This is especially discouraging to Microsoft. Any solution you can come up with will be a dirty hack that is likely to stop working soon.

Think of it this way: who should you solve these settings? Don't you think the user’s solution?

Back to the topic: Find an explicit format for applications you can chat with, such as YYYYMMDD. The displayed application can then simply respect the actual user settings, as it should be.

But, since you cannot change it, just paste it 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 one you want to change.

+14
source

If you are going to change the profile to suit your needs, why not just ignore the profile settings and hard code in the format you want in your application?

+2
source

the code:

 Imports System.Threading Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US", False) Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\Control Panel\International", "sShortDate", "M/d/yyyy") 
0
source

Source: https://habr.com/ru/post/1399348/


All Articles