• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
SCPreferencesLock issue?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: SCPreferencesLock issue?
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Scripting Bridge Strange Pauses
  • Next by Date: Re: SCPreferencesLock issue?
  • Previous by thread: Re: Why is NSPopUp broken in drop-down mode?
  • Next by thread: Re: SCPreferencesLock issue?
  • Index(es):
    • Date
    • Thread