【问题标题】:How to get Serial Number (processor tray) with Cocoa如何使用 Cocoa 获取序列号(处理器托盘)
【发布时间】:2012-07-23 13:56:46
【问题描述】:

通过键入:system_profiler SPHardwareDataType | grep '序列号' 我得到 2 个序列号。

第一个(“序列号(系统)”)可以放在NSString by :

(NSString *)IORegistryEntryCreateCFProperty(IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/"), CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0)

我没有找到如何获得第二个:序列号(处理器托盘)

有什么想法吗?

谢谢

【问题讨论】:

    标签: macos cocoa serial-number


    【解决方案1】:

    以更优雅的方式:)

    #import <Foundation/Foundation.h>
    
    int main()
    {
        CFTypeRef aCFProperty;
    
        if ((aCFProperty = IORegistryEntryCreateCFProperty(IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/"), CFSTR("processor-memory-board-serial-number"), kCFAllocatorDefault, 0)) != NULL )
        {
            NSLog(@"Processor tray Serial Number : %@", aCFProperty);
            CFRelease(aCFProperty);
        }
    
        return 1;
    }
    

    然后:clang SnTray.m -framework IOKit -framework Foundation -o SnTray.o

    然后./SnTray.o

    我不能做更多:)

    【讨论】:

      【解决方案2】:

      答案:

      (NSString *)IORegistryEntryCreateCFProperty(IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/"), CFSTR("processor-memory-board-serial-number"), kCFAllocatorDefault, 0);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-10
        • 2010-11-24
        • 2014-12-31
        • 1970-01-01
        • 2017-05-31
        • 2010-12-06
        • 2016-06-10
        • 2019-03-27
        相关资源
        最近更新 更多