Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
static extern uint IOServiceGetMatchingService(uint masterPort, IntPtr matching );
[DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
static extern IntPtr IOServiceMatching (string s);
[DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
static extern IntPtr IORegistryEntryCreateCFProperty(uint entry, IntPtr key, IntPtr allocator, uint options);
[DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
static extern int IOObjectRelease(uint o);
static string GetSerialNumber ()
{
string serial = string.Empty;
uint platformExpert = IOServiceGetMatchingService (0, IOServiceMatching ("IOPlatformExpertDevice"));
if (platformExpert != 0) {
NSString key = (NSString)"IOPlatformSerialNumber";
IntPtr serialNumber = IORegistryEntryCreateCFProperty (platformExpert, key.Handle, IntPtr.Zero, 0);
if (serialNumber != IntPtr.Zero) {
serial = new NSString (serialNumber);
}
IOObjectRelease (platformExpert);
}
return serial;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.