Step 1
First create a blank Windows Project. Name it ‘UniqueHardwareId’.
Step 2
In MainPage.xaml add a button with click event and a textbox to display the hardware id:
Complete XAML code
- <Page
- x:Class="UniqueHardwareId.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:UniqueHardwareId"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <Button x:Name="btnGetHwId" Content="Get Hardware ID" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="353,250,0,0" Height="99" FontSize="35" Width="743" Click="btnGetHwId_Click"/>
- <TextBox x:Name="txtId" HorizontalAlignment="Left" FontSize="30" TextWrapping="Wrap" VerticalAlignment="Top" Margin="356,409,0,0" Height="87" Width="737"/>
- </Grid>
- </Page>
In the code behind MainPage.xaml.cs, update code with,
- using System;
- using Windows.Storage.Streams;
- using Windows.System.Profile;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- namespace UniqueHardwareId
- {
- public sealed partial class MainPage: Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- }
- private void btnGetHwId_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var hardwareToken = HardwareIdentification.GetPackageSpecificToken(null);
- var hardwareId = hardwareToken.Id;
- var dataReader = DataReader.FromBuffer(hardwareId);
- byte[] bytes = new byte[hardwareId.Length];
- dataReader.ReadBytes(bytes);
- txtId.Text = BitConverter.ToString(bytes);
- } catch (Exception ex) {}
- }
- }
- }
Run the application, click on the button. You see the Hardware Id in the textbox field.

You can also get the complete project from GitHub.

Join the conversation! Your thoughts help the community grow.