How to access my computer's locale settings in the wpf app - c#

I have a WPF(Windows) App for which I need to get the locale of the user or the system where application is running. I have changed the locale of my system to French as shown in the image and in the code I call "CultureInfo.CurrentCulture.Name", which is returning en-US always even though I change the locale of the system. Am I missing something here? Or is this not the right API to be used?

To solve your problem you need to use Windows Sensor API
https://code.msdn.microsoft.com/windowsapps/Windows-7-Geolocation-API-25585fac

Related

Windows 10 assigned access app fails to start due to not registered for Windows.Launch contract

I have a WPF application, which I have converted to a UWP application using the DesktopAppConverter for the purposes of running it in Assigned Access mode - the converted app works when run in non-assigned access mode - can be installed and functions properly.
However, when I set it up to be used as an assigned access application and log in with the account for assigned access, the screen keeps flashing (blue screen with loading dots, followed by a white screen, and repeat) for a period of time, resulting in the 0x80270254 error displayed.
Also after checking the Windows Event Logs I get two error messages in succession:
The application MyAppName is not registered for the Windows.Launch contract or is not installed.
ActivateApplicationForContractByAppIdAsUserWithHost of the app MyAppName for the Windows.Launch contract failed with This app does not support the contract specified or is not installed.
I've been trying to debug the app, including making changes to the AppxManifest.xml file and rebuilding the .appx package, making changes to the properties of the original WPF app that it came from and making changes to the Assigned Access user account's environment with little to no success.
Any tips for the resolution of the issue would be much appreciated.
Thank you for reporting this issue.
We got the confirmation that the Assigned Access mode doesn’t support Win32 apps yet, including Win32 apps converted with the Desktop Converter.
It is a known issue in RS1 which can pick Converted app in setting UI. We have a planned fix for this in RS2 but do not guarantee it will be delivered soon.
Please see this article for how to use Shell Launcher to config a kiosk device that runs a Classic Windows application as the user interface: https://technet.microsoft.com/en-us/itpro/windows/manage/set-up-a-kiosk-for-windows-10-for-desktop-editions

How to set a static IP in a UWP?

I need to set a static IP address of a device with Windows 10 mobile. I am developing an Universal Windows App (UWP).
How can I do?
I tried following this article:
https://blogs.msdn.microsoft.com/softwaresimian/2014/09/10/setting-an-ip-to-address-to-be-static-and-then-dynamic-in-c/
But some of the classes are missing (like ManagementClass).
Not possible to affect system level settings from an app.
UWP applications are made to run in a sandbox. You won't have access to any APIs that change system settings or anything that could potentially change the behaviour of another application. At most you could have the application open the connection settings UI but it would be up to the user to perform actual changes.
The code that you reference should run in a WPF application or a console application. If you want to launch the Wi-Fi settings dialog you can use the following.
bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:network-wifi"));

C# Change System Location programmatically then reboot

I have a need to completely change the systems location and apply it to all accounts.
I now how to change threads but in this case I need to actually change the system location for all user accounts.
It will be a device running windows that will have a windows service that when it starts up will make a web service call back to a centrally hosted system that will tell it it's configuration including it's location. It then needs to change it's location (applying to all user accounts) and then reboot itself.
I know how to do this from the control panel but I need to pragmatically do it in C#
You can set the current user's geographical language by calling SetUserGeoID. And you can set a user's locale by calling SetLocaleInfo. However, that's just for the user account that is running the current program.
You'll need to use P/Invoke to call those methods. There might be prototypes and examples at pinvoke.net.
For copying to other users, I'm not sure. Sounds like something you'd do with WMI (Windows Management Instrumentation).
All settings are included in registry. [HKEY_USERS.DEFAULT\Control Panel\International] location. So you may change them in C# and reboot the system.

Process.Start specify culture

In one webapplication i have a IHttpHandler that when invoked starts an regular application that connects to a firebird database and amongst other things parses some dates from the database.
When run from the desktop the application does what is should without any problem. But when it is started from the httpHandler is ends up with the wrong culture and fails to parse the dates.
Ive set the culture i both web.config and CurrentThread.CurrentCulture but it still ends up with the wrong one.
All of this is run from an English Windows Server 2003 with the culture set to sv-SE.
So is there a way to start an application with System.Diganotics.Process.Start with a specific culture?
If there aren't which culture does the newly started process use?
I don't think there is a way to specify the culture. The CultureInfo class is specific to .NET, and as far as I know there is no app-specific notion of a culture in windows. There is no way to specify a culture using the Process and ProcessStartInfo classes.
However, I believe the culture is associated with the current user, so what may be happening, is that your Web app is running within a different user's context, so when started from the web app, the other app gets its' users' culture settings. Therefore, you could change the culture (regional settings) for the user that is used to run the web app.
On the other hand, if its' a .NET app you're running, you could just hardcode the culture into it.

Something wrong in the datetime format

When i compile the application in my laptop it runs fine but when i run the same application in the server something is wrong with the date format. But when i checked the system date time format wit my laptop and server it the same format. Can anyone tell me what is wrong.
You also have to check the default culture set in the laptop and the server. Are they running in the same culture? Different culture settings will have different default time formats.
Is your application running on the server under a different user account? Regional settings are per-user so date and time formats will depend on the user that the application is running under. You can log in as the application user and check the Regional settings to determine if that's the issue.
This is really common in ASP.NET where the developer builds the app on their workstation and upon deployment to QA or production they find that Regional settings differ because the App Pool is using a service identity.
Is the system clock running UTC, and the OS changing it to local time on the server. This is a pretty common configuration, but will break programs that bypass the OS's functions to retrieve the date/time.

Categories