Fetch workgroup / active directory domain name programatically in Obj-C / Swift

Previously, I used to have the below code to get workgroup / domain name of the active directory service provider.

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

On few Macs (probably starting from Sonoma), the workgroup property is not set. What is the alternative to get this information programatically?

Hmmm, that’s interesting. With System Configuration framework, the keys that are listed in <SystemConfiguration/SCSchemaDefinitions.h> are generally considered API. Both of the keys you’re using, SMB and Workgroup, are listed present [1], namely kSCEntNetSMB and kSCPropNetSMBWorkgroup, so I would expect this technique to continue to work.

Given that, I encourage you to file a bug about them being missing. Please post your bug number, just for the record.

The other place to get this info is from Open Directory. It’s been a long time since I’ve looked at this, so I’m a little fuzzy on the details. Can you find the info you need via dscl? If so, post the details and I can explain how to get the same info with the OD API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Much to my surprise!

Fetch workgroup / active directory domain name programatically in Obj-C / Swift
 
 
Q