如何从Mac硬盘获取序列号? [英] How to get serial number from Mac hard disks?
本文介绍了如何从Mac硬盘获取序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有任何简单的方法来获取Mac中使用任何API的所有硬盘的序列号?
Is there any easy way to get the serial number of all the hard disks in a Mac using any API's?
基本上寻找硬盘的唯一标识符,我应该知道,硬盘已被我的应用程序使用(推荐)。
Basically looking for a unique identifier for hard disk, with which I should make out that the Hard disk has been used(referred) by my application or not. Please let me know if there is any other solution.
注意:我需要10.4及以上版本的此解决方案。
Note: I need this solution in 10.4 and above.
推荐答案
我不知道AppleUSBEHCI是否是正确的寻找,但你可以使用IOKit框架检索这种数据:
I'm not sure if "AppleUSBEHCI" is the proper thing to look for but you can retrieve this sort of data using the IOKit framework:
#include <IOKit/IOKitLib.h>
#include <Cocoa/Cocoa.h>
kern_return_t kr;
io_iterator_t io_objects;
io_service_t io_service;
kr = IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceNameMatching("AppleUSBEHCI"), &io_objects);
if(kr != KERN_SUCCESS)
exit(1);
while((io_service= IOIteratorNext(io_objects)))
{
kr = IORegistryEntryCreateCFProperties(io_service, &service_properties, kCFAllocatorDefault, kNilOptions);
if(kr == KERN_SUCCESS)
{
NSDictionary * m = (NSDictionary *)service_properties;
NSLog(@"%@", m);
CFRelease(service_properties);
}
io_iterator_t iter;
//handle kr error
kr = IORegistryEntryGetChildIterator(io_service, kIOServicePlane, &iter);
io_registry_entry_t child;
while( (child = IOIteratorNext( iter )))
{
kr = IORegistryEntryCreateCFProperties(child, &child_props, kCFAllocatorDefault, kNilOptions );
NSLog(@"Child props: %@", child_props);
//release child_props
}
IOObjectRelease(io_service);
}
IOObjectRelease(io_objects);
这篇关于如何从Mac硬盘获取序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文