Page 1 of 1

An uninstallers last moments...

Posted: Wed Nov 30, 2005 10:33 pm
by utopiomania
Code updated For 5.20+

This is used in a 'drop in' installer I'm finishing, it's one of the last procedures called during an uninstall, and deletes the uninstaller,
and possibly (All = #True) the folder it resides in and everything in it including subfolders.

Code: Select all

Procedure DeleteThisPath(Path.s, All)
  ;Creates a script that deletes the calling program pointed to in
  ;path, and the script itself. If All = #True, the calling program
  ;folder, subfolders and files in them are deleted as well.
  
  ;Script file placed in the root of path
  Script.s = Left(Path, 2) + "\uninst"
  
  ;Ensure a unique script filename
  While(FileSize(Script.s + ".bat") > 0)
    ;File exists, test another name
    Script + Str(N)
    N + 1
  Wend
  ;Complete the script filename
  Script + ".bat"
  ;Create the script
  If CreateFile(0, Script)
    ;Reset file attributes
    WriteStringN(0,"attrib -h -r +a " + Chr(34) + Path + Chr(34))
    WriteStringN(0,":loop")
    WriteStringN(0,"del " + Chr(34) + Path + Chr(34))
    WriteStringN(0,"if exist " + Chr(34) + Path + Chr(34) + " goto loop")
    Dir.s = GetPathPart(Path)
    If All And Len(Dir) > 3 ;Dir not rootflder
      ;Reset folder, subfolders and file attributes
      WriteStringN(0,"attrib -h -r +a " + Chr(34) + Dir + Chr(34) + " /s /d")
      ;Quietly delete folder, subfolders and files
      WriteStringN(0,"rmdir " + Chr(34) + Dir + Chr(34) + " /s /q")
    EndIf
    ;Delete the script itself
    WriteStringN(0,"del " + Script)
    CloseFile(0)
    ;Run the script in invisible mode
    ProcedureReturn RunProgram(Script, "", "", 2)
  EndIf
  ProcedureReturn #False
EndProcedure

;To test create a similar folder to Path.s below, change Path.s,
;compile To an exe in the path then run it
Path.s = "F:\test\delete this path.exe"
MessageRequester("Delete", Path)

;Bye...
DeleteThisPath(Path, #True)
End


Posted: Wed Nov 30, 2005 10:35 pm
by Dare2
lol.

Haven't tried the code but I like the subject heading! :)

Posted: Wed Nov 30, 2005 11:47 pm
by rsts
Nice, but unnecessary since no one will ever want to uninstall one of your fine programs.

:lol:

cheers

Posted: Thu Dec 01, 2005 12:29 am
by utopiomania
@Dare2, my marketing skills are improving.. :) @Rsts, nice words, I'll try my best to live up to them :wink: