C
code_wrong
Hi,
I'm reading this:
http://www.catch22.net/tuts/selfdel.asp (Self Deleting Executables)
and playing around with the batch file method .. trouble is I always get a
command box at the end with the "the batch file cannot be found" message ..
how can I get rid of this .. while staying with the batch file method?
here is my code:
/*self deleting exe*/
#include <stdio.h>
int main(int argc,char* argv[])
{
if(argc == 1)//no arguments passed
{
/*create batch file*/
FILE *fp;
if((fp = fopen("self_delete.bat","wt")) == NULL)
{
fprintf(stderr, "Cannot open output file.\n");
return 1;
}
else
{
fputs("@echo off\n",fp);
fputs("start /wait .\\self_delete.exe code_wrong\n",fp);
fputs(":repeat\n",fp);
fputs("del .\\self_delete.exe\n",fp);
fputs("if exist \".\\self_delete.exe\" goto repeat\n",fp);
fputs("del .\\self_delete.bat >> NUL\n",fp);
fclose(fp);
}
/*call batch file*/
system("start .\\self_delete.bat");
return 0;
}
else if(!strcmp(argv[1],"code_wrong"))
{
/*do stuff when app called from self_delete.bat*/
int i;
for(i=0;i<500;i++)
{
printf("doing stuff\n");
}
}
else
{
printf("illegal arguments - exiting");
return 1;
}
return 0;
}
cheeeers
cw
I'm reading this:
http://www.catch22.net/tuts/selfdel.asp (Self Deleting Executables)
and playing around with the batch file method .. trouble is I always get a
command box at the end with the "the batch file cannot be found" message ..
how can I get rid of this .. while staying with the batch file method?
here is my code:
/*self deleting exe*/
#include <stdio.h>
int main(int argc,char* argv[])
{
if(argc == 1)//no arguments passed
{
/*create batch file*/
FILE *fp;
if((fp = fopen("self_delete.bat","wt")) == NULL)
{
fprintf(stderr, "Cannot open output file.\n");
return 1;
}
else
{
fputs("@echo off\n",fp);
fputs("start /wait .\\self_delete.exe code_wrong\n",fp);
fputs(":repeat\n",fp);
fputs("del .\\self_delete.exe\n",fp);
fputs("if exist \".\\self_delete.exe\" goto repeat\n",fp);
fputs("del .\\self_delete.bat >> NUL\n",fp);
fclose(fp);
}
/*call batch file*/
system("start .\\self_delete.bat");
return 0;
}
else if(!strcmp(argv[1],"code_wrong"))
{
/*do stuff when app called from self_delete.bat*/
int i;
for(i=0;i<500;i++)
{
printf("doing stuff\n");
}
}
else
{
printf("illegal arguments - exiting");
return 1;
}
return 0;
}
cheeeers
cw