SCPreferencesLock issue?
SCPreferencesLock issue?
- Subject: SCPreferencesLock issue?
- From: Jeremy Matthews <email@hidden>
- Date: Fri, 17 Sep 2010 03:43:32 -0400
For some reason, I can't seem to get a lock....was wondering if anyone else has been here before:
AuthorizationRef auth = nil;
OSStatus authErr = noErr;
AuthorizationFlags rootFlags = kAuthorizationFlagDefaults
| kAuthorizationFlagExtendRights
| kAuthorizationFlagInteractionAllowed
| kAuthorizationFlagPreAuthorize;
authErr = AuthorizationCreate(nil, kAuthorizationEmptyEnvironment, rootFlags, &auth);
SCPreferencesRef prefs;
//SCPreferencesRef prefsWithAuth;
CFStringRef appName = CFSTR("com.test.testapp");
CFStringRef computerName = CFSTR("macbookpro2");
SCPreferencesLock(prefs, NO);
if ( geteuid() != 0 )
{
prefs = SCPreferencesCreateWithAuthorization(NULL, appName, NULL, auth);
}
else
{
prefs = SCPreferencesCreate(NULL, appName, NULL);
}
if (prefs == nil)
NSLog(@"InterfaceConfig failure: SCPreferencesCreate failed");
SCPreferencesLock(prefs, NO);
if (prefs && SCPreferencesLock(prefs, TRUE))
{
//We got a write lock, that means we can do whatever
//we want to /Library/Preferences/SystemConfiguration/preferences.plist
NSLog(@"LOCK OBTAINED");
} else {
NSLog(@"LOCK NOT OBTAINED");
}
SCPreferencesSetComputerName(prefs, computerName, kCFStringEncodingUTF8);
SCPreferencesCommitChanges(prefs);
if(!SCPreferencesCommitChanges(prefs))
{
NSLog(@"can't commit changes");
}
SCPreferencesApplyChanges(prefs);
if(!SCPreferencesApplyChanges(prefs))
{
NSLog(@"can't apply changes");
}
SCPreferencesUnlock(prefs);
CFRelease(prefs);
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden