Windows服务无法获得正确的系统文化

dan*_*ely 2 .net c# cultureinfo currentculture

从控制面板,我将我的区域和语言设置设置为法语(法国)

当我将应用程序作为控制台应用程序运行时,

Thread.CurrentThread.CurrentCulture 返回法语

但是,当我将它作为Windows服务运行时,它会返回不变的文化或英语(美国)

有办法解决这个问题吗?

Sha*_*lde 9

该服务可能以具有自己文化的用户身份运行.

为什么不在开始服务时设置文化

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
Run Code Online (Sandbox Code Playgroud)

也来自Windows服务中的默认文化

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".
Run Code Online (Sandbox Code Playgroud)

我通常使用前一种技术,因为我只需要为特定服务而不是整个操作系统更改它.