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

How do I tokenize a string in c++?

839


Is dev c++ a good compiler?

727


What are virtual functions in c++?

927


What is std namespace in c++?

931


Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).

821


List different attributes in C++?

851


Is c++ built on c?

790


What are guid?

986


What is increment operator in c++?

788


Can char be a number c++?

817


What is the type of 'this' pointer?

810


Describe the role of the c++ in the tradeoff of safety vs. Usability?

975


What are static variables?

848


What is the difference between multiple and multilevel inheritance in c++?

909


Write about the local class and mention its use?

843