Delete self?

Hi,

is there any way to add code to delete self, like, you will run program, it will do something and then delete his .exe? I don't know how to do it cuz it gives me error because that program is running, this is what I have:

1
2
3
4
5
6
7
8
9
10
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
	system("copy testlol.exe ..\\testlol.exe");
	cin.get();
	system("del testlol.exe");
}
Last edited on
Is Google so hard to use? That's what I used to find this:
http://www.cplusplus.com/reference/clibrary/cstdio/remove/

Also, High risk of a s***storm abrewing regarding your use of the evil system(). Go to the link below and read post #8.
http://www.dreamincode.net/forums/topic/18057-run-external-executable/
Last edited on
well, I wanna delete program that will execute command to delete, so I will run testlol.exe, it will copy self to another folder and then delete self from first folder, remove function don't works too...
Last edited on
¿So you want to move your file? rename() it.
yes I wanna move it, not rename...
look, I have program in
D:\ called testlol.exe,
so I have
D:\testlol.exe
this program will copy self to D:\test\ so I will have
D:\test\testlol.exe AND
D:\testlol.exe
------ until now it works fine
BUT now I wanna delete that testlol from D:\, so I will have:

D:\test\testlol.exe ONLY ... NO MORE D:\testlol.exe

and I need to do that by just running that testlol.exe in D:\, nothing else
Last edited on
Impossible, windows keeps the file stream open for a program, so it can't delete itself. You should run the copy and pass it your current path and then exit, allowing the copy to delete the original.
Topic archived. No new replies allowed.