phooey! .. The batch file cannot be found

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
 
C

code_wrong

code_wrong said:
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*/

/********************************************/
I replace this: system("start .\\self_delete.bat");
with this : ShellExecute(0,"open",".\\self_delete.bat",0,0,0);
and it works like a dream .. of course I had to #include <windows.h>
to make this API call which bumps up the exe size .. but then
I don't have an application for this program yet ... let me think
/********************************************/
cheers
cw
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top