Deleting an exe.

Hi, I have been able to deploy a vb.net project onto some systems, which basically downloads latest files and then the main project handles all the updates from that point forward. So what I would like to be able to do is to delete the exe I install after it has done the download. How can i do this? I know this must be very easy code, but I very new to vb.net,....pls help...

Comments

  • If what your asking is how to make an EXE delete itself, then the problem you are probably running into is an access denied error because the exe is currently running. The only way I've ever found around this is to write a batch file, then run the batch file and exit immediately afterwards. I don't know exactly why this works, but from experimenting, it appears to me that when you run a batch file from in your code that there are certain functions that will wait until your code is completed before they execute in the system. I would venture to say that the delete command is one of them...

    Here's what you do to write a batch file.

    Keep in mind I haven't had to do this in .net yet, but I'm sure it works just as well here as it did in 6.0


    Write a file that looks like the following one from within your code. Replace C:Appname with your exe path, replace C:Batname with the path of the batch file you are going to create, and save it with a ".bat" extention

    [code]

    Del C:Appname
    Del C:Batname

    [/code]

    The batch file will delete itself just fine. This will all happen so fast, that by the time windows updates, you will never even know there was a batch file there. It will look just like your application just disapeared.

    One problem I run into with creating batch files, is that I wanted to ping something once, and so I made my program write a batch file that said "Ping 127.0.0.1 >> C:SomePathSomeFile.txt". This is supposed to send the results to a file that I could pick up, but unfortunately, my theory that windows holds off on certain commands until your program exits, it wouldn't write the file until my program exited. So I couldn't pick it up. The way I got around this was to write to batch files, and one of them ran the other. The one I would call that ran the other could do this immediately, then when that batch file exited, the file from the second was written to disk and I could pick it up in a matter of about 2 or 3 miliseconds. (I set the timeout to be very short on the ping).

    I am sure there was a better way to ping, but I needed a solution right away and wasn't aware of any simple API calls, or internal VB6.0 functions that could do this for me.

    ANyways, I hope some of this helped you at all.




    ><//~Psightoplasm`~

  • : If what your asking is how to make an EXE delete itself, then the problem you are probably running into is an access denied error because the exe is currently running. The only way I've ever found around this is to write a batch file, then run the batch file and exit immediately afterwards. I don't know exactly why this works, but from experimenting, it appears to me that when you run a batch file from in your code that there are certain functions that will wait until your code is completed before they execute in the system. I would venture to say that the delete command is one of them...
    :
    : Here's what you do to write a batch file.
    :
    : Keep in mind I haven't had to do this in .net yet, but I'm sure it works just as well here as it did in 6.0
    :
    :
    : Write a file that looks like the following one from within your code. Replace C:Appname with your exe path, replace C:Batname with the path of the batch file you are going to create, and save it with a ".bat" extention
    :
    : [code]
    :
    : Del C:Appname
    : Del C:Batname
    :
    : [/code]
    :
    : The batch file will delete itself just fine. This will all happen so fast, that by the time windows updates, you will never even know there was a batch file there. It will look just like your application just disapeared.
    :
    : One problem I run into with creating batch files, is that I wanted to ping something once, and so I made my program write a batch file that said "Ping 127.0.0.1 >> C:SomePathSomeFile.txt". This is supposed to send the results to a file that I could pick up, but unfortunately, my theory that windows holds off on certain commands until your program exits, it wouldn't write the file until my program exited. So I couldn't pick it up. The way I got around this was to write to batch files, and one of them ran the other. The one I would call that ran the other could do this immediately, then when that batch file exited, the file from the second was written to disk and I could pick it up in a matter of about 2 or 3 miliseconds. (I set the timeout to be very short on the ping).
    :
    : I am sure there was a better way to ping, but I needed a solution right away and wasn't aware of any simple API calls, or internal VB6.0 functions that could do this for me.
    :
    : ANyways, I hope some of this helped you at all.
    :
    :
    :
    :
    : ><//~Psightoplasm`~
    :
    :

    I'm not sure, but will this work?:
    [code]
    dim filename As String
    filename = Application.Filename (Can't remember code for App's Filename)
    Kill(filename)
    [/code]

  • :
    : I'm not sure, but will this work?:
    : [code]
    : dim filename As String
    : filename = Application.Filename (Can't remember code for App's Filename)
    : Kill(filename)
    : [/code]
    :
    No... an application can't delete itself because it is still running.

    ><//~Psightoplasm`~

  • You could create a seperate application to kill your application and call it through a shell command from the application to be deleted. And set the Shell command to wait until after the program closes.


    :
    : :
    : : I'm not sure, but will this work?:
    : : [code]
    : : dim filename As String
    : : filename = Application.Filename (Can't remember code for App's Filename)
    : : Kill(filename)
    : : [/code]
    : :
    : No... an application can't delete itself because it is still running.
    :
    : ><//~Psightoplasm`~
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories