below is a sourcecode to write an uninstaller which delete itself after running (goto deleteItself ) , no restart or Batchfile needed .
this version used the possibility to run code from stack
; Delete running exe, by PB. Works under all versions of Windows.
MessageBox_(0,"This exe will self-destruct when you click OK","Test",0)
RunProgram(GetEnvironmentVariable("comspec"),"/c del "+Chr(34)+ProgramFilename()+Chr(34),"",2)
[Edit] Updated for v4.02 on June 4, 2007 by myself. Much shorter now!
Last edited by PB on Mon Jun 04, 2007 10:50 am, edited 3 times in total.
;For our purposes, consider "target.exe" to be your main
;application. "Transit.exe" is the source file used to
;replace your main application. The following code would
;be placed near the top of your main code or wherever you
;think most convenient. By placing it inside your main
;application, you force the installation update even if
;the user is unaware that an update is available. You
;can insert code into your main application to allow the
;user to bypass the update if desirable.
; SKIP THIS BLOCK IF NO UPDATE "FILE" AVAILABLE
If FileSize("C:\mypath\install.exe") > 0
;
; ON THE 1ST PASS ** LAUNCH UPDATE & QUIT **
If FileSize("C:\mypath\transit.exe") > 0 ;(our new target.exe)
RunProgram("C:\mypath\install.exe","","")
End ; QUIT!!! target.exe to allow installation update!!!
;
; Meanwhile install.exe procedes as follows:
; Delete target.exe (your old app)
; Rename transit.exe as target.exe
; LAUNCH THE NEW TARGET.EXE
; exit install.exe
;
Else
; ON THE 2ND PASS ** TIDY UP & RESUME **
DeleteFile("C:\mypath\install.exe")
;transit.exe didn't exist so remove the installer.
;The update is either complete or transit.exe was not
;available to replace the old target.exe file.
EndIf
EndIf
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
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.
I like logic, hence I dislike humans but love computers.