Page 1 of 1
Mac license info
Posted: Fri Sep 09, 2016 1:00 am
by Keya
In Windows, in registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion there's a "ProductID" string key with value along the lines of "23423412-2312-234234-12423434", which for the most part is unique to each purchased license. I'm just wondering is there something similar on Mac OSX?
Re: Mac license info
Posted: Fri Sep 09, 2016 1:07 am
by jack
have you tried About This Mac/System Report ?
Re: Mac license info
Posted: Fri Sep 09, 2016 2:19 am
by Keya
yes i believe its the Serial Number field, but how as a programmer do we access this?
Re: Mac license info
Posted: Fri Sep 09, 2016 5:16 am
by wilbert
Tested with PB 5.42
Code: Select all
ImportC ""
IOServiceGetMatchingService(masterPort, matching)
IOServiceMatching(name.p-ascii)
EndImport
platformExpert = IOServiceGetMatchingService(#Null, IOServiceMatching("IOPlatformExpertDevice"))
If platformExpert
serialNumberKey = CocoaMessage(0, 0, "NSString stringWithString:$", @"IOPlatformSerialNumber")
serialNumberAsCFString = IORegistryEntryCreateCFProperty_(platformExpert, serialNumberKey, #Null, 0)
If serialNumberAsCFString
Debug PeekS(CocoaMessage(0, serialNumberAsCFString, "UTF8String"), -1, #PB_UTF8)
CFRelease_(serialNumberAsCFString)
EndIf
IOObjectRelease_(platformExpert)
EndIf
Re: Mac license info
Posted: Fri Sep 09, 2016 8:46 am
by Keya
working fine straight out of the box here, thankyou!!! CocoaMessage to the rescue again, I'm hoping the day will quickly come that my brain "gets" it! i have no idea how you figured out how to do that, and then for example if you found Objective C code how you knew to port it over to PB. One day i will understand! lottts of reading still to do in the meantime, lol
Re: Mac license info
Posted: Fri Sep 09, 2016 8:53 am
by wilbert
Keya wrote:i have no idea how you figured out how to do that
I converted the second solution that was posted on this page
http://stackoverflow.com/questions/1973 ... ial-number 
Re: Mac license info
Posted: Fri Sep 09, 2016 9:30 am
by Keya
Ahh!!! it looks like it might be a great little study piece for people like me wanting to learn porting like this, Rosetta stone style. COFFEE TIME!
Code: Select all
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
// Returns the serial number as a CFString.
// It is the caller's responsibility to release the returned CFString when done with it.
void CopySerialNumber(CFStringRef *serialNumber)
{
if (serialNumber != NULL) {
*serialNumber = NULL;
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert) {
CFTypeRef serialNumberAsCFString =
IORegistryEntryCreateCFProperty(platformExpert,
CFSTR(kIOPlatformSerialNumberKey),
kCFAllocatorDefault, 0);
if (serialNumberAsCFString) {
*serialNumber = serialNumberAsCFString;
}
IOObjectRelease(platformExpert);
}
}
}
Re: Mac license info
Posted: Sun Sep 11, 2016 8:37 pm
by Shardik
Since this is a solution which doesn't uitilize the Cocoa framework, I had already posted an example nearly 4 years ago (it also displays the UUID and Wilbert even modified it to also work on x64 and with Unicode...

):
http://www.purebasic.fr/english/viewtop ... 81&start=5
Re: Mac license info
Posted: Sun Sep 11, 2016 9:00 pm
by wilbert
Shardik wrote:Since this is a solution which doesn't uitilize the Cocoa framework, I had already posted an example nearly 4 years ago (it also displays the UUID and Wilbert even modified it to also work on x64 and with Unicode...

):
http://www.purebasic.fr/english/viewtop ... 81&start=5
I didn't remember
