Self Deleting Exe after Running (new version)

Share your advanced PureBasic knowledge/code with the community.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Joakim Christiansen wrote:

Code: Select all

If ProgramParameter(0)
  DeleteDirectory(Left(ProgramParameter(0),Len(ProgramParameter(0))-1),"*.*",#PB_FileSystem_Recursive|#PB_FileSystem_Force)
  comspec$=Space(255): GetEnvironmentVariable_("comspec",comspec$,255)
  RunProgram(comspec$,"/c del "+#DQUOTE$+GetPathPart(ProgramFilename())+#DQUOTE$,"")
Else
  If MessageRequester("Uninstall","Are you shure you want to completely remove this folder and all the files in it?",#MB_ICONQUESTION|#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
    CopyFile(ProgramFilename(),GetTemporaryDirectory()+"TVUninstall.exe")
    RunProgram(GetTemporaryDirectory()+"TVUninstall.exe",#DQUOTE$+GetPathPart(ProgramFilename())+#DQUOTE$,"")
  EndIf
EndIf
Tried running it from the temp-directory like this and then delete the directory I gave it in a parameter, but it didn't work.
In first place, i guess it will fails because your program is running and you can't delete a directory that have a running file.

And using "If ProgramParameter(0) " its a little dangerosu because some exe receives a program parameter many times, per example when running from a shortcut, etc.

I think you have to make sure that receives certain parameter before trying to delet anything.

One more point is that you should not delete the whole directory in which your app is running... and what about if for any reason people moves the executable to C:\?????

A uninstall must use some ini file or something that tells WHAT files and directories you create and you can only delete those ones. Can't asume that the directory in which the program is running is the same, its dangerous, very dangerous.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

ricardo wrote:One more point is that you should not delete the whole directory in which your app is running... and what about if for any reason people moves the executable to C:\?????
Yeah, you got a point there!
I like logic, hence I dislike humans but love computers.
Post Reply