Skip to main content

Windows 8 System Info

I talked about uniquely identifying a Windows 8 device before. Last week I stumbled over this post by Rene Schulte.  In this post he creates the SystemInformation class. This class gathers some useful information about the current system and dumps it in a string:

using System;
using System.Globalization;
using System.IO;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Store;
using Windows.Devices.Enumeration;
using Windows.Devices.Input;
using Windows.Graphics.Display;
using Windows.Networking.Connectivity;
using Windows.Security.ExchangeActiveSyncProvisioning;
using Windows.Storage;
using Windows.System.Profile;
using Windows.System.UserProfile;
using Windows.UI.Xaml;

namespace Schulte.Xaml.Windows
{
public class SystemInformation
{
public static async Task<string> Dump(bool shouldDumpCompleteDeviceInfos = false)
{
var builder = new StringBuilder();
var packageId = Package.Current.Id;
var clientDeviceInformation = new EasClientDeviceInformation();

// Get hardware Id
var token = HardwareIdentification.GetPackageSpecificToken(null);
var stream = token.Id.AsStream();
string hardwareId;
using (var reader = new BinaryReader(stream))
{
var bytes = reader.ReadBytes((int)stream.Length);
hardwareId = BitConverter.ToString(bytes);
}

builder.AppendLine("***** System Infos *****");
builder.AppendLine();
#if DEBUG
builder.AppendLine("DEBUG");
builder.AppendLine();
#endif
builder.AppendFormat("Time: {0}", DateTime.Now.ToUniversalTime().ToString("r"));
builder.AppendLine();
builder.AppendFormat("App Name: {0}", packageId.Name);
builder.AppendLine();
builder.AppendFormat("App Version: {0}.{1}.{2}.{3}", packageId.Version.Major, packageId.Version.Minor, packageId.Version.Build, packageId.Version.Revision);
builder.AppendLine();
builder.AppendFormat("App Publisher: {0}", packageId.Publisher);
builder.AppendLine();
builder.AppendFormat("Supported Package Architecture: {0}", packageId.Architecture);
builder.AppendLine();
builder.AppendFormat("Installed Location: {0}", Package.Current.InstalledLocation.Path);
builder.AppendLine();
builder.AppendFormat("Store App Id: {0}", CurrentApp.AppId);
builder.AppendLine();
if (CurrentApp.LicenseInformation.IsActive)
{
var listingInformation = await CurrentApp.LoadListingInformationAsync();
builder.AppendFormat("Store Current Market: {0}", listingInformation.CurrentMarket);
builder.AppendLine();
}
builder.AppendFormat("Culture: {0}", CultureInfo.CurrentCulture);
builder.AppendLine();
builder.AppendFormat("OS: {0}", clientDeviceInformation.OperatingSystem);
builder.AppendLine();
builder.AppendFormat("System Manufacturer: {0}", clientDeviceInformation.SystemManufacturer);
builder.AppendLine();
builder.AppendFormat("System Product Name: {0}", clientDeviceInformation.SystemProductName);
builder.AppendLine();
builder.AppendFormat("System Sku: {0}", clientDeviceInformation.SystemSku);
builder.AppendLine();
builder.AppendFormat("System Name: {0}", clientDeviceInformation.FriendlyName);
builder.AppendLine();
builder.AppendFormat("System ID: {0}", clientDeviceInformation.Id);
builder.AppendLine();
builder.AppendFormat("Hardware ID: {0}", hardwareId);
builder.AppendLine();
builder.AppendFormat("User Display Name: {0}", await UserInformation.GetDisplayNameAsync());
builder.AppendLine();
builder.AppendFormat("Window Bounds w x h: {0} x {1}", Window.Current.Bounds.Width, Window.Current.Bounds.Height);
builder.AppendLine();
builder.AppendFormat("Current Orientation: {0}", DisplayProperties.CurrentOrientation);
builder.AppendLine();
builder.AppendFormat("Native Orientation: {0}", DisplayProperties.NativeOrientation);
builder.AppendLine();
builder.AppendFormat("Logical DPI: {0}", DisplayProperties.LogicalDpi);
builder.AppendLine();
builder.AppendFormat("Resolution Scale: {0}", DisplayProperties.ResolutionScale);
builder.AppendLine();
builder.AppendFormat("Is Stereo Enabled: {0}", DisplayProperties.StereoEnabled);
builder.AppendLine();
builder.AppendFormat("Supports Keyboard: {0}", IsKeyboardPresent());
builder.AppendLine();
builder.AppendFormat("Supports Mouse: {0}", IsMousePresent());
builder.AppendLine();
builder.AppendFormat("Supports Touch (contacts): {0} ({1})", IsTouchPresent(), new TouchCapabilities().Contacts);
builder.AppendLine();
builder.AppendFormat("Is Network Available: {0}", NetworkInterface.GetIsNetworkAvailable());
builder.AppendLine();
builder.AppendFormat("Is Internet Connection Available: {0}", NetworkInformation.GetInternetConnectionProfile() != null);
builder.AppendLine();
builder.AppendFormat("Network Host Names: ");
foreach (var hostName in NetworkInformation.GetHostNames())
{
builder.AppendFormat("{0} ({1}), ", hostName.DisplayName, hostName.Type);
}
builder.AppendLine();
builder.AppendFormat("Current Memory Usage: {0:f3} MB", GC.GetTotalMemory(false) / 1024f / 1024f);
builder.AppendLine();
builder.AppendFormat("App Temp Folder: {0}", ApplicationData.Current.TemporaryFolder.Path);
builder.AppendLine();
builder.AppendFormat("App Local Folder: {0}", ApplicationData.Current.LocalFolder.Path);
builder.AppendLine();
builder.AppendFormat("App Roam Folder: {0}", ApplicationData.Current.RoamingFolder.Path);
builder.AppendLine();
builder.AppendLine();

if (shouldDumpCompleteDeviceInfos)
{
var devInfos = await DeviceInformation.FindAllAsync();
//builder.AppendLine("CPU Info:");
//foreach (var devInfo in devInfos.Where(d => d.Name.ToLower().Contains("cpu")))
//{
// builder.AppendFormat("Name: {0} Id: {1} - Properties: ", devInfo.Name, devInfo.Id);
// foreach (var pair in devInfo.Properties)
// {
// builder.AppendFormat("{0} = {1}, ", pair.Key, pair.Value);
// }
// builder.AppendLine();
//}

builder.AppendLine();
builder.AppendLine("Complete Device Infos:");
foreach (var devInfo in devInfos)
{
builder.AppendFormat("Name: {0} Id: {1} - Properties: ", devInfo.Name, devInfo.Id);
foreach (var pair in devInfo.Properties)
{
builder.AppendFormat("{0} = {1}, ", pair.Key, pair.Value);
}
builder.AppendLine();
}
}

return builder.ToString();
}

public static bool IsTouchPresent()
{
return new TouchCapabilities().TouchPresent == 1;
}

public static bool IsMousePresent()
{
return new MouseCapabilities().MousePresent == 1;
}

public static bool IsKeyboardPresent()
{
return new KeyboardCapabilities().KeyboardPresent == 1;
}
}
}

Popular posts from this blog

.NET 8–Keyed/Named Services

A feature that a lot of IoC container libraries support but that was missing in the default DI container provided by Microsoft is the support for Keyed or Named Services. This feature allows you to register the same type multiple times using different names, allowing you to resolve a specific instance based on the circumstances. Although there is some controversy if supporting this feature is a good idea or not, it certainly can be handy. To support this feature a new interface IKeyedServiceProvider got introduced in .NET 8 providing 2 new methods on our ServiceProvider instance: object? GetKeyedService(Type serviceType, object? serviceKey); object GetRequiredKeyedService(Type serviceType, object? serviceKey); To use it, we need to register our service using one of the new extension methods: Resolving the service can be done either through the FromKeyedServices attribute: or by injecting the IKeyedServiceProvider interface and calling the GetRequiredKeyedServic...

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...