-
-
Save chamons/82ab06f5e83d2cb10193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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