How to write a program such that it will delete itself after
exectution?

Answers were Sorted based on User's Feedback



How to write a program such that it will delete itself after exectution?..

Answer / pranjali

I guess if your program name is program.c the last line of
your code should be the operating system call to to delete
the file "program.c".

once you compile it to get a .exe , the existance of
program.c is immeterial.

you will hv to take care of necessary error handling.

Is This Answer Correct ?    2 Yes 2 No

How to write a program such that it will delete itself after exectution?..

Answer / siva

this code is tested succesfully.

#include <windows.h>

#include <iostream>
#include <stdio.h>

#include <string.h>

using namespace std;

int main(int arg, int argv[])
{

STARTUPINFO si;
PROCESS_INFORMATION pi;
STARTUPINFO sj;
PROCESS_INFORMATION pj;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

ZeroMemory( &sj, sizeof(sj) );
sj.cb = sizeof(sj);
ZeroMemory( &pj, sizeof(pj) );

if(!CreateProcess("C:\\Windows\\system32
\\cmd.exe", "/k del C:\\testp.exe", NULL, NULL, FALSE, 0,
NULL, NULL, &sj, &pj))
{
printf( "Hello CreateProcess failed (%d)\n",
GetLastError() );
}

return 0;
}

Is This Answer Correct ?    2 Yes 2 No

How to write a program such that it will delete itself after exectution?..

Answer / ven

I am not sure but I guess create a destructor

Is This Answer Correct ?    2 Yes 10 No

Post New Answer

More C++ General Interview Questions

What is data hiding c++?

0 Answers  


What is the use of cmath in c++?

0 Answers  


Is c++ the hardest language?

0 Answers  


List the special characteristics of constructor.

0 Answers  


What problem does the namespace feature solve?

1 Answers  






Can we inherit constructor in c++?

0 Answers  


implement stack using stack.h headerfile functions

1 Answers   Exilant, GMG, Subex, University,


What is pointer to member?

0 Answers  


What is a driver program?

0 Answers  


can output 5 students using one dimensional array

1 Answers   Intel,


Is c++ a good beginners programming language?

0 Answers  


Is c++ still being used?

0 Answers  


Categories