system commands. deletion of file after program terminates
:confused:
Is there a way to delete an executable after terminating itself?
I want to delete my program after it has finished running.
We are required to write a stack that when overloaded it restarts your machine and on reboot it reloads the data and deletes itself out of the startup folder? I keep getting access violations when trying to delete it while it is still running. Is there a command I can run to execute the delete after the program has completed running? Below is the error in the quote and also a selection from my code.
Thanks for any help this provides.
X
Quote:
C:\Documents and Settings\All Users\Start Menu\Programs\Startup\Stack Array.exe
Access is denied.
Code:
void stacked::read()
{
system("del \"C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup\\Stack Array.exe\"");
ifstream instream("C:/overflow.dat");
if(instream)
{
dirtball();
for(int x=0;x<=SIZE-1;x++)
{
instream>>dataPtr[x];
}
instream>>leftDepth;
instream>>rightDepth;
instream>>nummies;
}
display();
cout<<"Press any key"<<endl;
getch();
instream.close();
}