Mac license info

Mac OSX specific forum
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Mac license info

Post 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?
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Mac license info

Post by jack »

have you tried About This Mac/System Report ?
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Mac license info

Post by Keya »

yes i believe its the Serial Number field, but how as a programmer do we access this?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Mac license info

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Mac license info

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Mac license info

Post 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 :wink:
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Mac license info

Post 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);
        }
   }
}
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Mac license info

Post 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... :wink:):
http://www.purebasic.fr/english/viewtop ... 81&start=5
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Mac license info

Post 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... :wink:):
http://www.purebasic.fr/english/viewtop ... 81&start=5
I didn't remember :oops:
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply