• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: System serial number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: System serial number


  • Subject: Re: System serial number
  • From: Werner Sinnhoefer <email@hidden>
  • Date: Tue, 15 Jul 2003 09:43:09 +0200

Hi!

Seems like all Macs have a serial number. You can get it from the
IORegistry. Here is how I pick it up ( and pack it into a string which
will be formated as the one you see in the "About this Mac" dialog):

-(NSString*)serialNumberString

{
NSString *result = @"";
mach_port_t masterPort;
kern_return_t kr = noErr;
io_registry_entry_t entry;
CFDataRef propData;
CFTypeRef prop;
CFTypeID propID;
UInt8 *data;
unsigned int i, bufSize;
char *s, *t;
char firstPart[64], secondPart[64];

kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (kr == noErr) {
entry = IORegistryGetRootEntry(masterPort);
if (entry != MACH_PORT_NULL) {
prop = IORegistryEntrySearchCFProperty(entry, kIODeviceTreePlane,
CFSTR("serial-number"), NULL, kIORegistryIterateRecursively);
propID = CFGetTypeID(prop);
if (propID == 5) {
propData = (CFDataRef)prop;
bufSize = CFDataGetLength(propData);
if (bufSize > 0) {
data = CFDataGetBytePtr(propData);
if (data) {
i = 0;
s = data;
t = firstPart;
while (i < bufSize) {
i++;
if (*s != '\0') {
*t++ = *s++;
} else {
break;
}
}
*t = '\0';

while ((i < bufSize) && (*s == '\0')) {
i++;
s++;
}

t = secondPart;
while (i < bufSize) {
i++;
if (*s != '\0') {
*t++ = *s++;
} else {
break;
}
}
*t = '\0';
result = [NSString stringWithFormat:@"%s%s", secondPart,
firstPart];
}
}
}
}
mach_port_deallocate(mach_task_self(), masterPort);
}
return(result);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: System serial number
      • From: "Alastair J.Houghton" <email@hidden>
  • Prev by Date: Re: disabling font smoothing...
  • Next by Date: Overriding description
  • Previous by thread: Re: System serial number
  • Next by thread: Re: System serial number
  • Index(es):
    • Date
    • Thread