How to delete .exe itsellf- Answer..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prakashsakthivel
    New Member
    • Oct 2007
    • 57

    How to delete .exe itsellf- Answer..

    Dear Members

    I asked one problem that how to delete .exe itself after some days..

    I got solution.

    I want to tell about that to all members

    we can do easily.
    [code=vb]
    Open App.Path + "\" + App.EXEName + ".bat" For Output As #1
    'Print #1, "sleep 10"
    Print #1, ":loop"
    Print #1, "If Not exist " & Chr(34) & App.Path + "\" + App.EXEName + ".exe" & Chr(34); " goto :ends"
    Print #1, "del " & Chr(34) & App.Path + "\" + App.EXEName + ".exe" & Chr(34)
    Print #1, "goto loop"
    Print #1, ":ends"
    Print #1, "del " & Chr(34) & App.Path + "\" + App.EXEName + ".bat" & Chr(34)
    Close #1

    Then call shell function.
    Call Shell(App.Path + "\" + App.EXEName + ".bat", vbHide)
    [/code]
    Actually, as per microsoft shell function is running asynochrounly as default

    so no problem to make self destructing .exe

    Regards

    Prakash.S
    Last edited by debasisdas; Feb 11 '08, 05:35 AM. Reason: added code=vb tags
  • vdraceil
    New Member
    • Jul 2007
    • 236

    #2
    Hi,i really dont understand ur code.it is vb6.0,isnt it?Can u explain it pls..

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Originally posted by vdraceil
      Hi,i really dont understand ur code.it is vb6.0,isnt it?Can u explain it pls..
      The code is using file handling and finally Shell .

      Refer to Vb articles in HowTo section of the forum for file handling..

      Comment

      • lotus18
        Contributor
        • Nov 2007
        • 865

        #4
        Nice codes

        This can be helpful if you want to promote your application as beta.

        Comment

        • gearboxcomputers
          New Member
          • Apr 2008
          • 1

          #5
          Thought I would supply a working Sub Procedure.

          I have added the END statement as well as an ErrorHandler to make it fully functional...

          Paste it into a vb6 project, and call the function from a command button or such.

          Code:
          Public Sub SelfDelete()
              On Error GoTo ErrorHandler
              Open App.Path + "\" + App.EXEName + ".bat" For Output As #1
                  'Print #1, "sleep 10"
                  Print #1, ":loop"
                  Print #1, "If Not exist " & Chr(34) & App.Path + "\" + App.EXEName + ".exe" & Chr(34); " goto :ends"
                  Print #1, "del " & Chr(34) & App.Path + "\" + App.EXEName + ".exe" & Chr(34)
                  Print #1, "goto loop"
                  Print #1, ":ends"
                  Print #1, "del " & Chr(34) & App.Path + "\" + App.EXEName + ".bat" & Chr(34)
                  Close #1
                  
              'Then call shell function.
                 Call Shell(App.Path + "\" + App.EXEName + ".bat", vbHide)
                 [U][B]'Notice the End statement.  This makes it all work[/B][/U]
                 [B]End[/B]
          ErrorHandler:
              'Catch any errors here if something goes wrong.
          End Sub
          Thanks for the original post :)

          Comment

          • lotus18
            Contributor
            • Nov 2007
            • 865

            #6
            It's been awhile since the codes have been updated. Ahh...

            Comment

            Working...