Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Last active November 17, 2020 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennykerr/f26b54ae861d0710dac31f97411239d9 to your computer and use it in GitHub Desktop.
Save kennykerr/f26b54ae861d0710dac31f97411239d9 to your computer and use it in GitHub Desktop.
Reading the computer's serial number
#include "winrt/Windows.System.Profile.SystemManufacturers.h"
using namespace winrt::Windows::System::Profile::SystemManufacturers;
int main()
{
winrt::init_apartment();
printf("Serial number = %ls\n", SmbiosInformation::SerialNumber().c_str());
}
@kennykerr
Copy link
Author

This example was inspired by Raymond Chen's post.

@DBJDBJ
Copy link

DBJDBJ commented Jan 9, 2018

The first two includes in Raymond's code where especially troublesome :)

@DBJDBJ
Copy link

DBJDBJ commented Jan 11, 2018

Out of sheer curiosity ... why the printf ? AFAIK in no code of yours, you use std::cout ?

@kennykerr
Copy link
Author

Mainly personal preference. Both are problematic in different ways. printf is always faster and often more concise.

@DBJDBJ
Copy link

DBJDBJ commented Jan 18, 2018

True indeed. Although printf() with a lot of arguments is tedious to get right, but then those examples are rare.

@iecompattest
Copy link

fdksjfklfd

@AriKrumbein
Copy link

Question: Why do you omit the

winrt::init_apartment();
...
winrt::clear_factory_cache();
winrt::uninit_apartment();

or more importantly, why does he include them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment