473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

phooey! .. The batch file cannot be found

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
Nov 14 '05 #1
1 4696

"code_wrong" <ta*@tac.ouch.co.uk> wrote in message
news:10****************@eunomia.uk.clara.net...
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
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Luis P. Mendes | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 hi, I've already read many pages on this but I'm not able to separate the string 'R0\1.2646\1.2649\D' in four elements, using the \ as the...
12
by: Mark A. Gibbs | last post by:
i have a question about class design, specifically regarding accessor functions. which is probably a better design? class foo { public: void name(string const& n) { name_ = n; } string name()...
12
by: Dave | last post by:
Can anyone tell me, is it legal for a class to have the same name as the namespace it is in. I did it, and the compiler didn't give an error, but it caused some very odd name resolving problems....
6
by: Hong Kong Phooey | last post by:
I feel dumb asking this, haveing programmed in VB for so long, but here goes... What is the rule for putting an ampersand (&) at the END of a hexadecimal number in VB? For example: Dim x As...
5
by: Hong Kong Phooey | last post by:
I wrote a control in which I overrode WndProc to implement a custom MouseMove. I caught the MouseMove message and passed it to a function which raises a custom event. In this function I get the x...
18
by: chump1708 | last post by:
union u { struct st { int i : 4; int j : 4; int k : 4; int l; // or int l:4 }st; int i;
14
by: John Welch | last post by:
Hi all. I'm creating a FE/BE database that will be used by about 6 users. As usual, I have several fields, such as "OrganizationTypeID" that will get values (via combo boxes in forms) from separate...
1
by: Csaba Gabor | last post by:
Short version: if the user types an alt+ctrl+char combination which leads to a defined character, but s/he's not in a input(text)/textarea, then I'd like that keystroke combination to do the same...
15
by: Jon Davis | last post by:
Bill Wagner posted something here .. http://msdn2.microsoft.com/en-us/vcsharp/default.aspx "Local Type Inference, Anonymous Types, and var" "Of all the features in C# 3.0, local type inference...
3
by: ITAutobot25 | last post by:
Now this is really the last problem (for real now) with this assignment. My sorter is not working. I managed to sort by product name in my previous assignment; however, I can't get it to work on this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.