简体   繁体   中英

Mac os x get domain name programmatically

I know about windows workgroup and iwant to get workgroup of my Mac. As i see Open Directory directory domain name on Mac OS X but could not get rid of my problem. I wish to find the workgroup (as in Windows) of my Mac. Please give me some code example to go ahead towards solution. I want domain name as desribed in http://windows.microsoft.com/en-in/windows7/what-is-the-difference-between-a-domain-a-workgroup-and-a-homegroup

The System Configuration framework is a C api, so it's a little bit messy, but this should work ok without leaking:

#import <SystemConfiguration/SCNetworkConfiguration.h>

SCDynamicStoreRef storeRef = SCDynamicStoreCreate(NULL, (CFStringRef)@"GetWorkgroup", NULL, NULL);
CFPropertyListRef global = SCDynamicStoreCopyValue (storeRef,CFSTR("State:/Network/Global/SMB"));
id workgroup = [(__bridge NSDictionary *)global valueForKey:@"Workgroup"];
NSLog(@"Workgroup: %@", workgroup);
CFRelease(global);
CFRelease(storeRef);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM