How to write a program such that it will delete itself after
exectution?
Answers were Sorted based on User's Feedback
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 |
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 |
What is ofstream c++?
What is a pointer how and when is it used?
Explain about profiling?
Which is best c++ or java?
Write a Program to find the largest of 4 no using macros.
What do you mean by “this” pointer?
What does getch() do according to the ANSI C++ standard a) Reads in a character b) Checks the keyboard buffer c) Nothing in particular (Its not defined there)
What is the full form of dos?
What is the difference between a "copy constructor" and an "assignment operator" in C++?
What is the most useful programming language?
What is endl?
Explain how a pointer to function can be declared in C++?