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 Destructor in C++?

953


Define a nested class.

835


What is #include iomanip?

758


Name the implicit member functions of a class.

845


What are the extraction and insertion operators in c++?

776


What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.

801


Is c++ vector a linked list?

779


Why cout is used in c++?

769


What is the difference between the parameter to a template and the parameter to a function?

897


What is a literal in c++?

763


Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

744


Can comments be longer than one line?

816


What are the uses of static class data?

878


write a program that withdrawals,deposits,balance check,shows mini statement. (using functions,pointers and arrays)

2049


How do you declare A pointer to a function which receives nothing and returns nothing

949