Page 1 of 1

Delete your own Exe (For UnInstaller )

Posted: Tue Nov 18, 2003 2:08 pm
by Rings
Code updated for 5.20+

Code: Select all

Procedure UninstallApp()
  sApp.s = Space(256)
  GetModuleFileName_(GetModuleHandle_(0), @sApp, 256)        
  MessageRequester("Info", "Hit me to delete myself..." + 
                            Chr(13) + sApp, 0)
  OpenFile(1, "~~uninst.bat")
  WriteStringN(1, "del " + GetFilePart(sApp))
  WriteStringN(1,"del ~~uninst.bat")
  CloseFile(1)
  RunProgram("~~uninst.bat")
EndProcedure            

UninstallApp()

Posted: Fri Jan 16, 2004 5:08 pm
by Le Soldat Inconnu
This code don't work on windows XP.

It run on win 2000 or win98 but on win xp, the *.bat file is not correctly execute.

Someone has a solution ?

thanks.

this can

Posted: Fri Jan 16, 2004 6:21 pm
by thefool
Thanks to his idea i did this. It works, and is much smaller.
Why use so many lines in the batch file?
Anyway, thanks for the api command giving you the filename.,

Code: Select all

;Get app's filename
sApp.s=Space(256) 
GetModuleFileName_(GetModuleHandle_(0), @sApp, 256)
;Little message  
MessageRequester("hello","Push this button to delete this app.")
appfile.s=GetFilePart(sApp.s) ;Get file part...
;Writing batch file...
OpenFile(1,"tmp.bat")
WriteStringN("del "+appfile.s)
WriteStringN("del tmp.bat")
CloseFile(1)
;Execute the file
RunProgram("tmp.bat")
;Done!

Re: this can

Posted: Fri Jan 16, 2004 7:30 pm
by Berikco
thefool wrote:Why use so many lines in the batch file?
Because its possible the batch file is finished before your program is ended. So the batch file cant delete a running program, a check in a loop is needed...

Re: this can

Posted: Wed Mar 17, 2004 8:20 pm
by ricardo
Berikco wrote:
thefool wrote:Why use so many lines in the batch file?
Because its possible the batch file is finished before your program is ended. So the batch file cant delete a running program, a check in a loop is needed...
Its almost secure that if you 'runprogram()', the bat will run when your app is open, you are right.

The first example runs fine here in XP pro.

Posted: Fri Mar 19, 2004 3:33 am
by Wayne Diamond
Hrmmm. Rings didn't write this, he just ported my Powerbasic code that i wrote back in 2002:
http://www.powerbasic.com/support/forum ... 01350.html

Posted: Fri Mar 19, 2004 9:31 am
by Anden
Without batch (could be troublesome with different OSes):

Create exe "RestartExe":

Code: Select all

exename.s = StringField(ProgramParameter(), 1, " ")
HomeDir.s = StringField(ProgramParameter(), 2, " ")
i.b = 0
While (DeleteFile(exename) = 0 And i <= 10)
  Delay(250) ;wait for old exe to quit
  i = i + 1
Wend
CopyFile(HomeDir+"Transfer\_#_2A-ChitChat_Upd.exe", exename)
DeleteFile(HomeDir+"Transfer\_#_2A-ChitChat_Upd.exe")
RunProgram(exename, "", GetPathPart(exename))
End
Include this in your main exe:

Code: Select all

DataSection
RestartExe: IncludeBinary "RestartExe.exe"
_RestartExe:
EndDataSection

Procedure.s MyExeName()
  File$ = Space(512)
  GetModuleFileName_(GetModuleHandle_(#NULL), @File$, 512)
  ProcedureReturn File$
EndProcedure

CreateFile(68, HomeDir+"RestartExe.exe")
WriteData(?RestartExe, ?_RestartExe-?RestartExe)
CloseFile(68)
If (MessageRequester("Restart 2A-ChitChat", "Received new client version "+text+" from server."+cr+cr+"Press <OK> to restart or <CANCEL> to quit program.", #MB_OKCANCEL|#MB_ICONQUESTION|#MB_TASKMODAL) = #IDOK) ;yes
  RunProgram(HomeDir+"RestartExe.exe", MyExeName()+" "+HomeDir, HomeDir, 2)
EndIf
Should work too (although it's somehow bloated :-))

Posted: Sun Mar 28, 2004 2:27 pm
by Manne
For nt-based systems there is an easier way.
common

Code: Select all

; PureBasic Visual Designer v3.82 build 1356
DefType.s Filename, tmp
NewList Dateien.s()
osvi.OSVERSIONINFO

;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Listview_0
  #Button_0
  #Button_1
  #Button_2
  #Image_0
EndEnumeration

;- Statusbar Constants
;
Enumeration
  #StatusBar_0
EndEnumeration

;- Image Plugins
UseJPEGImageDecoder()

;- Image Globals
Global Image0

;- Catch Images
Image0 = CatchImage(0, ?Image0)

;- Images
DataSection
Image0:
  ;IncludeBinary "F:\sicherung\dottore.jpg"
EndDataSection

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 339, 204, 302, 236,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Delay File Delete 1.0")
    If CreateStatusBar(#StatusBar_0, WindowID())
      AddStatusBarField(302)
      StatusBarText(#StatusBar_0, 0, "Bereit")
    EndIf
    If CreateGadgetList(WindowID())
      ListViewGadget(#Listview_0, 10, 10, 180, 200, #LBS_SORT)
      ButtonGadget(#Button_0, 210, 10, 80, 30, "Auswählen")
      ButtonGadget(#Button_1, 210, 50, 80, 30, "Löschen")
      ButtonGadget(#Button_2, 210, 90, 80, 30, "Beenden")
      ;ImageGadget(#Image_0, 210, 130, 80, 80, Image0, #PB_Image_Border)
      
    EndIf
  EndIf
EndProcedure
main

Code: Select all

; PureBasic Visual Designer v3.82 build 1356

IncludeFile "Common.pb"

osvi\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
GetVersionEx_(osvi)
If osvi\dwPlatformId <> #VER_PLATFORM_WIN32_NT Or osvi\dwMajorVersion = 4
  MessageRequester("Fehler", "Windows 9x/ME wird nicht unterstützt!", #MB_ICONSTOP)
  End
EndIf

Open_Window_0()
DisableGadget(#Button_1, 1)

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_EventCloseWindow
    quit = 1
  ElseIf Event = #PB_Event_Gadget
    Select EventGadgetID()
      Case #Listview_0
        
      Case #Button_0  ; Auswählen
        Filename = OpenFileRequester("Datei(en) auswählen", "C:\", "Alle Dateien (*.*)|*.*", 0, #PB_Requester_MultiSelection)
        Repeat
          AddElement(Dateien())
          Dateien() = Filename
          SendMessage_( GadgetID(#Listview_0), #LB_ADDSTRING, 0, GetFilePart(Filename))
          Filename = NextSelectedFileName()
        Until Filename = ""
        DisableGadget(#Button_1, 0)
        
      Case #Button_1  ; Löschen
        ForEach Dateien()
          SetFileAttributes_(Dateien(), #FILE_ATTRIBUTE_NORMAL)
          MoveFileEx_(Dateien(), #NULL, #MOVEFILE_DELAY_UNTIL_REBOOT)
        Next
        ClearGadgetItemList(#Listview_0)
        StatusBarText(#StatusBar_0, 0, "Dateien werden nach dem nächsten Neustart gelöscht!") 
         
      Case #Button_2  ; Beenden
        quit = 1
        Break
    EndSelect
  EndIf
    
Until quit
End
;
Manne