Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 an array

20 Answers  


Explain data encapsulation?

0 Answers  


What is time_t c++?

0 Answers  


how to find the maximum of 10 numbers ?

5 Answers  


Define a way other than using the keyword inline to make a function inline?

1 Answers  


What is a tuple c++?

0 Answers  


What is abstraction in c++ with example?

0 Answers  


What is a character in c++?

0 Answers  


Is java made in c++?

0 Answers  


Write a program to find the Fibonacci series recursively.

0 Answers   Huawei,


what does the following statement mean? int (*a)[4]

0 Answers  


What is object slicing and how can we prevent it?

2 Answers   Tech Mahindra,


Categories