Re: how to delete the current user's directory?
Re: how to delete the current user's directory?
- Subject: Re: how to delete the current user's directory?
- From: "Michael Ash" <email@hidden>
- Date: Mon, 1 Sep 2008 10:02:42 -0400
On Mon, Sep 1, 2008 at 6:46 AM, XiaoGang Li <email@hidden> wrote:
> hi, list, I have an uninstaller application , which is used to delete
> the files installed; and also i have a file which located in the current
> user's directory, like the ~/Library/LaunchAgents/com.****.plist. and how
> can i delete this kind of file, i have tried the
> AuthorizationExecuteWithPrivileges
> API, it seems not workable, do i give a wrong flag value or something else?
> here is my code piece, any comments will be appreciated.
>
> AuthorizationRef myAuthorizationRef;
>
> AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
>
> AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,myFlags,
> &myAuthorizationRef);
>
> AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0};
>
> AuthorizationRights myRights = {1, &myItems};
>
>
>
> myFlags = kAuthorizationFlagDefaults |
>
> kAuthorizationFlagInteractionAllowed |
>
> kAuthorizationFlagPreAuthorize |
>
> kAuthorizationFlagExtendRights;
>
> AuthorizationCopyRights (myAuthorizationRef, &myRights, NULL, myFlags, NULL);
>
>
> char *fileDir = "~/Library/LaunchAgents/com.hp.printerAgent.plist";
>
> char* args[3];
>
> args[0]= "-Rf";
>
> args[1]= fileDir;
>
> args[2]= NULL;
>
>
> myFlags = kAuthorizationFlagDefaults;
>
> OSStatus res = AuthorizationExecuteWithPrivileges(myAuthorizationRef,
> "/bin/rm",myFlags,args,NULL);
>
> AuthorizationFree(myAuthorizationRef, myFlags);
>
>
> and the res value is -60032. and by the way, how can i get the current
> user's name string? which cocoa API can get it?
There should be no need to use AuthorizationExecuteWithPrivileges. You
should have permission to delete any file within the user's home
directory.
As for why you're failing, you'll want to look at this page:
http://www.cocoadev.com/index.pl?NSTaskArguments
It talks about NSTask, but the same principle applies to
AuthorizationExecuteWithPrivileges or NSFileManager (which is what I
recommend you use). That ~ character is not something that they know
about, which is why you're seeing the problem.
Mike
_______________________________________________
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