Detect When Running on Windows Simulator

The Windows Simulator is a deployment target for Visual Studio which allows you to run your Windows Store apps in a simulated device. This allows you to test touch interaction and different screen sizes and orientations on your development machine. The way this works is that it creates a Remote Desktop session into your PC. This is why when you run it you’ll see your own start screen and user account. The problem with this is that some APIs fail on the simulator such as setting up a Push Notification channel. We need a way to detect if we are running in the simulator so that we can react accordingly. If you try to poke around for hardware information you’ll find it returns the same as running directly on your machine. This makes sense when you know it’s a Remote Desktop session. Luckily there is an API specifically designed for this scenario:-

This will return true in a Simulator session. We can use this to avoid calling any code which will fail on the simulator and can easily switch between local machine and simulator deployment to test various aspects of the app without touching the code or using different project configurations and conditional compilation.