Recent

Author Topic: Cant remove files  (Read 4518 times)

slicke

  • New Member
  • *
  • Posts: 12
Cant remove files
« on: September 22, 2016, 10:51:49 pm »
Hi!

I'm writing an uninstaller.
The thing is that when I try modify anything - it doesn't work.

I can verify that a file exists, but not remove it..

For instance, I tried to remove a directory:
Code: Pascal  [Select][+][-]
  1.     r:=DeleteDirectory(x,True);
  2.     if r then begin
  3.         r := RemoveDirUTF8(x);
  4.     end;    
  5.  

I get no errors, but the directory is still there.
I tried running the app with sudo and
'security execute-with-privileges /usr/bin/open '+Application.ExeName, from the app itself (relaunching it).

I have no luck calling things via fpsystem or tprocess either...

Is there some security thing that might prevent me from doing this? Ive tried accessing /Library/XX and /Application/XX

Thanks!

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Cant remove files
« Reply #1 on: September 23, 2016, 12:39:36 am »
What are you trying to "uninstall"? An app? If so, you're likely going about it wrong, since normally uninstalling an app on OS X only requires dragging the app bundle to the Trash. That's it. No uninstaller needed.

Maybe you're uninstalling a group of data files or libraries or something? If so, please give more information.


slicke

  • New Member
  • *
  • Posts: 12
Re: Cant remove files
« Reply #2 on: September 23, 2016, 12:49:32 pm »
Thanks for replying.

The app has data in both /Library/app and /Applications/app awell as a launchd file. Its installed via a .pkg.

My app is supposed to clean all those files which a normal trashing doesn't do :)

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Cant remove files
« Reply #3 on: September 23, 2016, 01:01:23 pm »
Capable programmers are supposed to resolve those simple issues themselves.
(Heey, it's Friday, I am grumpy again).
Specialize a type, not a var.

slicke

  • New Member
  • *
  • Posts: 12
Re: Cant remove files
« Reply #4 on: September 23, 2016, 01:26:35 pm »
I didn't write the original program. I was just tasked with wiring an uninstaller :P So I agree that it's a bad situation :)

slicke

  • New Member
  • *
  • Posts: 12
Re: Cant remove files
« Reply #5 on: September 23, 2016, 02:55:16 pm »
Actually it seems that in OS X, even if your app is running in privileged mode, you need to add sudo in your tprocesses, like:

Code: Pascal  [Select][+][-]
  1.   for x in pids do begin
  2.     RunCommand('sudo', ['kill', '-9', x], result);  

That works, without any error messages or dialogs - when I execute the app with a launch sript:
sudo open -a App.app

:)

slicke

  • New Member
  • *
  • Posts: 12
Re: Cant remove files
« Reply #6 on: September 23, 2016, 06:46:45 pm »
I created a launcher in AppleScript:
Code: AppleScript  [Select][+][-]
  1. set current_path to POSIX path of ((path to me as text) & "::")
  2. do shell script ("sudo '" & current_path & "remover.app/Contents/MacOS/remover'") with administrator privileges
  3.  

I am not proud of it, but it does run my app with admin privileges (like Windows' UAC) in a very very ugly way  %)

I compiled that as a binary-only script application and it just fires up and asks for admin credentials.

Maybe theres someone else with a better solution though? I'm a bit ashamed of this one...

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Cant remove files
« Reply #7 on: September 23, 2016, 06:59:14 pm »

 

TinyPortal © 2005-2018