Results 1 to 14 of 14

Thread: Self killing program (after execution)

  1. #1

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482

    Self killing program (after execution)

    Hi all,
    I want that my program will kill itself after executing.
    How to do this?
    To be clear, I don't want to make for any ill purpose...
    Help...
    Anita
    Can't imagine life without VB
    (Various Boyfriends)

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    kill app.path & "\myprog.exe"

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    That wont work, because the executable is in use, and can't be deleted.

    You could create a (temporary) batch file, that deletes the executable, and after that deletes itself (a batch file can delete itself). Shell the batch file and immediately close the program.

    There could be a timing problem though, because the executable could not be finished closing itself when the batch file tries to delete it. I think it is best to put the code in the terminate event, so it executes as late as possible (you have to put something like Set Form1 = Nothing in the unload event, otherwise the terminate event isn't triggered).

    I remember that this question has been asked before, so you could try to search for something like "program delete itself"

  4. #4
    Addicted Member mr_metal_hed's Avatar
    Join Date
    Aug 2002
    Location
    NC
    Posts
    149
    Does that actually work? I always add a line to the rename section of Wininit.ini to delete my program.

    [rename]
    NUL=C:\MyProg.exe


    Of course this doesn't happen until the next reboot. Ever notice on loading windows shows "Please wait. Updating your file configuration" or something.... it's deleting files etc. This is how a lot of programs delete their components when you uninstall them.

    You can read about doing this here & here

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Of course that is another option. There is an API function (MoveFileEx) that can delete a file at the next reboot.

    Pass MOVEFILE_DELAY_UNTIL_REBOOT for the dwFlags parameter, and pass vbNullString for lpNewFileName.

    This is for NT based OS's

    For win 9x you need to use the method mr_metal_hed mentioned.

  6. #6

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482
    Originally posted by phinds
    kill app.path & "\myprog.exe"
    Hi Phinds,
    I tried it..but it sems to be not working...
    i think its not working as the exe is running.
    U can't kill/delete the file if it is running..
    Anyone explan??
    Can't imagine life without VB
    (Various Boyfriends)

  7. #7

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482
    Thanks Frans C and mr_metal_hed,
    But still not clear to me..
    Any better way?
    Anyone will give me code?
    Thanks in Advance...
    Anita
    Can't imagine life without VB
    (Various Boyfriends)

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Attached is a sample program that will delete itself. Basically what is does is it write a batch file that will attempt delete the exe. It will loop until the exe is deleted and then it deletes the batch file.

    Go ahead and compile the app and place it somewhere where it is easy to watch. Run it and close it and watch it disappear.
    Attached Files Attached Files

  9. #9
    Addicted Member mr_metal_hed's Avatar
    Join Date
    Aug 2002
    Location
    NC
    Posts
    149
    Anyone will give me code?
    That kind of takes the fun out of it, doesn't it? besides, you never specified the OS...

  10. #10
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    would it be alright if you installed 2 exes.. the self deleting one and a time-delay deleting one? That way they would keep the deleting one. You could make it like

    Sub Form_Terminate()
    Shell "C:\MYTIMEDELAYEDKILL.EXE " & app.path & app.exename & ".exe"
    End Sub

    Would that work?
    If I agree with you today, don't get used to it.

  11. #11

    Here is the Ans.

    Hai,

    Killing means u can't delete the file,
    But u can make the program run once only.

    This can be done by creating a flat file if it is not there and exiting if it is there. First time it will create the file and executes, From second time onwards it exits simply as the file is already there.

    Ok.

    [email protected]
    Ravindra

  12. #12
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    That wont work, because the executable is in use, and can't be deleted
    I can only blame my brain dead response on the fact that I hadn't yet had breakfast when I posted.

    Sounds like MarkT has the solution

  13. #13

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482
    Originally posted by mr_metal_hed
    That kind of takes the fun out of it, doesn't it? besides, you never specified the OS...
    Hi mr_metal_hed, I agree with u. But sometimes u needs the program ASAP. Isn't it? Otherwise no problem.
    Can't imagine life without VB
    (Various Boyfriends)

  14. #14

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482
    Originally posted by MarkT
    Attached is a sample program that will delete itself. Basically what is does is it write a batch file that will attempt delete the exe. It will loop until the exe is deleted and then it deletes the batch file.

    Go ahead and compile the app and place it somewhere where it is easy to watch. Run it and close it and watch it disappear.
    Thank You very much MarkT,
    Nice code and working fine...It solved my problem..
    Million Thanks
    Last edited by anita2002; Aug 30th, 2002 at 07:17 AM.
    Can't imagine life without VB
    (Various Boyfriends)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width