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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is capacity in vector in c++?

637


Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?

643


write a function signature with various number of parameters.

667


What are literals in C++?

674


How do you establish an is-a relationship?

705






When are exception objects created?

686


How do you show the declaration of a virtual constructor?

612


What is buffering in c++?

668


Describe exception handling concept with an example?

642


What are static variables?

694


What are maps in c++?

591


Describe new operator and delete operator?

730


What is function overloading c++?

662


what is upcasting in C++?

823


Describe new operator?

698