Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service Unable to get correct System Culture

From Control Panel, I set my Region and Language setting to French (France)

When I am running my application as console application,

Thread.CurrentThread.CurrentCulture returns French

But when I'm running it as windows service, it returns invariant culture or English (US)

Is there a way to fix that?

like image 812
daniely Avatar asked Oct 31 '25 19:10

daniely


1 Answers

The service is probably running as a user that has it's own culture.

Why not set the culture when you start your service

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

Also from Default Culture in a Windows Service

If your Windows Service is running under the SYSTEM account or other account without a 
profile it will use the settings defined under the 
"HKEY_USERS/.DEFAULT/Control Panel/International" registry key.  

You can change these values from "Control Panel / Regional and Language Options / Advanced" 
by checking the checkbox "Apply all settings to the current user account and to the default 
user profile".

I normally use the former technique as I only need to change it for a specific service rather than for the whole OS.

like image 161
Shaun Wilde Avatar answered Nov 02 '25 09:11

Shaun Wilde