It is currently Sun Aug 18, 2019 3:59 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject:
PostPosted: Sun Jan 19, 2003 6:22 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by MrVainSCL.

Hi @ all!
Finally i found a way how to delete your running app automatical, like some uninstallers do the job. I need this routine for an own install/uninstaller system and think maybe someone is interested to learn about the following (maybe danger) code...

Maybe there is any other and better methode... But i dont know and for the first time it seems to works fine...

Code:
; ------------------------------------------------------------
;
; PureBasic Win32 API - MyDeleteRunningApp - Example v1.0
;
; by MrVainSCL! aka Thorsten   19/Jan/2003    PB v3.51+
;
; ------------------------------------------------------------
;
    Procedure MyDeleteRunningApp()
        ;
        ; -------- Get application filename --------
        ;
        a$ = Space(1024)
        GetModuleFilename_(0,@a$,1024)           
        appname$ = GetFilePart(a$)               
        ;
        ; -------- Create script file (uninstall) --------     
        ;
        OpenFile(0,"tmp.bat")
          WriteStringN(":loop")
          WriteStringN("del "+appname$)   ;programm.exe")
          WriteStringN("if exist "+appname$+" Goto loop")
          WriteStringN("del tmp.bat")
        CloseFile(0)
        ;
        ; -------- Execute script and delete running app --------
        ;
        ShellExecute_(0,"open","tmp.bat",0,0,#SW_SHOW)
        ;
    EndProcedure
    ;
    ; -------- We will quit, so delete running app --------
    ;   
    MessageRequester("Delete running app","Will now delete your running app!",0)
    MyDeleteRunningApp()                               
End
;
; ------------------------------------------------------------


Create an executeable to any directory and test it... After starting this application a small requester appears, the program will quit and the file you have started is now deleted!


PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jan 22, 2003 2:59 am 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by PB.

> Maybe there is any other and better methode...

Hi MrVain,

Your tip works well but has one problem: if the executable name has a
space in it, it fails. So change the appname$ line to this instead, and
it'll work with any executable name:

appname$=Chr(34)+GetFilePart(a$)+Chr(34)

Also, to stop the batch file from briefly popping up (which looks bad),
change the #SW_SHOW flag to #SW_HIDE instead -- much better! :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jan 22, 2003 10:46 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by MrVainSCL.

Ok PB, i have noticed it - thanks! :)

greetz
MrVainSCL! aka Thorsten

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 26, 2003 11:23 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed May 21, 2003 1:44 pm
Posts: 119
Location: Netherlands
Whynot just do getshortfilename from windows api, it returnd the dos filename..../path aka 6chrs~1


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Sep 25, 2006 1:55 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Jun 02, 2005 3:55 am
Posts: 501
Location: U.S.A.
BackupUser wrote:
<i>Restored from previous forum. Originally posted by <b>PB</b>.</i><br /><br /> > Maybe there is any other and better methode...<br /><br />Hi MrVain,<br /><br />Your tip works well but has one problem: if the executable name has a<br />space in it, it fails. So change the appname$ line to this instead, and<br />it'll work with any executable name:<br /><br />appname$=Chr(34)+GetFilePart(a$)+Chr(34)<br /><br />Also, to stop the batch file from briefly popping up (which looks bad),<br />change the #SW_SHOW flag to #SW_HIDE instead -- much better! <img src="images/smiles/icon_smile.gif" /><br />


Q.

Is there a time I should use Chr(34) over say "?

_________________
Intrigued - Registered PureBasic, lifetime updates user


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Sep 25, 2006 1:10 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7439
Location: Norway
If you use " you end the string.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Sep 25, 2006 3:22 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 855
Location: Germany
I use following code for EasySetup:
Code:
Procedure SelfDestruct(ProgDir$="")
  exe$ = ProgramFilename()
  bat$ = Left(exe$,1)+":\~~uninst.bat"
  If ProgDir$ And Right(ProgDir$,1) = "\" : ProgDir$ = Left(ProgDir$,Len(ProgDir$)-1) : EndIf
  If CreateFile(0, bat$)
    WriteStringN(0, "cd \")
    WriteStringN(0, ":DeleteFile")
    WriteStringN(0, "del "+Chr(34)+exe$+Chr(34)) ;program executable
    WriteStringN(0, "if exist "+Chr(34)+exe$+Chr(34)+" goto DeleteFile")
    If ProgDir$
      WriteStringN(0, "rd "+Chr(34)+ProgDir$+Chr(34)) ; program directory
    EndIf
    WriteStringN(0, "del "+Chr(34)+bat$+Chr(34)) ; temporary batch file
    WriteStringN(0, "exit")
    CloseFile(0)
    ShellExecute_(0,"open",bat$,0,0,#SW_HIDE)
  EndIf
EndProcedure

_________________
Sorry for my English. My language is German.
(Translated with http://www.DeepL.com/Translator)

Download of PureBasic - Modules (GitHub)

[Windows 10 x64] [PB V5.7x]


Last edited by Thorsten1867 on Fri Oct 27, 2006 4:05 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 26, 2006 5:42 pm 
Offline
Addict
Addict
User avatar

Joined: Tue May 10, 2005 10:00 pm
Posts: 1648
Location: Norway
Note that the last script fails if the path to the program contains characters DOS can't handle.

Even though DOS can handle long filenames, it can not handle some filenames that are perfectly ok in Windows.


Top
 Profile  
Reply with quote  
 Post subject: Re: Win32 - Delete running application (uninstall)
PostPosted: Mon Oct 05, 2009 2:52 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8004
Location: Fort Nelson, BC, Canada
I'm surprised to find this one isn't posted here, I got it from user PB some time back and it seems quite reliable:

Code:
RunProgram(GetEnvironmentVariable("comspec"),"/c del "+Chr(34)+ProgramFilename()+Chr(34),"", #PB_Program_Hide)

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: Win32 - Delete running application (uninstall)
PostPosted: Tue Oct 06, 2009 12:20 am 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1251
Nice ways.
I have used another way. But that is a long time ago. It worked on Win95 don't know if it works on newer OS's. I think it's not the best way anyway. Just telling it for fun:

I copied the own .exe to the recycle.bin directory on c: and executed it there with a parameter to tell it to delete the original .exe and the path to it. Then terminated the original .exe. The copied .exe in recycle.bin waited for the original to terminate and deleted it. The next time the recycle bin was been cleared the copied .exe was gone.

utopiomania wrote:
Note that the last script fails if the path to the program contains characters DOS can't handle.

Even though DOS can handle long filenames, it can not handle some filenames that are perfectly ok in Windows.

This is true only for Win9x. On NT based OS's bat files are not executed by command.com and can handle anything that windows can.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye