self deletable .exe

K

Keith Thompson

Clemens Auer said:
bit shorter and typo save ..
;-)

<code>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
remove(*argv);
return 0;
}
</code>

One of the many ways this can go wrong: On Unix-like systems, argv[0]
is not necessarily the full name of the program, particularly if it
was executed via $PATH. For example, if you install the program as
"foo", executing it will likely (attempt to) delete the file "foo" in
your current directory, not the executable.

More generally, the value of argv[0] represents the program name, but
that doesn't necessarily mean that it can be used as a file name
pointing to the executable.
 
J

Jack Klein

That's nasty

The OP, a homework phisher if ever there was one, asked "How to make
self deletable .exe file such that during runtime the file delete
itself from the current path."

There was no mention of a requirement to refrain from deleting
anything else.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
R

ROSY

hello,
thats work good.then how can i delete the .exe automatically on
some future date.
thanks.
bye



Clemens Auer said:
bit shorter and typo save ..
;-)

<code>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
remove(*argv);
return 0;
}
</code>

PS: your questions sounds lot like homework...

ROSY said:
1.How to make self deletable .exe file such that during runtime the
file delete itself from the current path.

#include <stdio.h>
#include <string.h>
int main(void) {
char buffer[100];
printf("What is the name of this .exe file?\n");
fgets(buffer, sizeof buffer, stdin);
if (buffer[strlen(buffer)-1] == '\n')
buffer[strlen(buffer)-1] = '\0';
remove(buffer);
return 0;
}

--
/-- Joona Palaste ([email protected])
---------------------------\| Kingpriest of "The Flying Lemon Tree"
G++ FR FW+ M- #108 D+ ADA N+++|| http://www.helsinki.fi/~palaste
W++ B OP+
|\----------------------------------------- Finland rules!
------------/"Remember: There are only three kinds of people - those
who can count and those who can't."
- Vampyra
 
J

Joona I Palaste

ROSY said:
hello,
thats work good.then how can i delete the .exe automatically on
some future date.

You can't, in ISO standard C.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"You will be given the plague."
- Montgomery Burns
 
L

LibraryUser

ROSY said:
thats work good.then how can i delete the .exe automatically on
some future date.

Find some newsgroup with "job" in its title. Post an ad there,
reading something like:

Reliable small boy wanted to type "rm whatever.exe" into my
system on YYYY.MM.DD. Payment in advance.

Adjust the command and date to suit. Select carefully from the
applicants. Pay the successful applicant and go back to sleep.

DO NOT POST that ad on c.l.c. It is off-topic here.
 
K

Keith Thompson

hello,
thats work good.then how can i delete the .exe automatically on
some future date.

The "remove(*argv);" trick may happen to work when you test it, but it
is absolutely not guaranteed to work under all circumstances. On many
systems, it can easily delete some arbitrary file in your current
directory rather than the running executable. Other possibilities are
that the remove() will simply fail because *argv does not contain the
actual file name of the executable, and that it will fail because the
operating system does not allow a currently running executable to be
deleted.

There is no portable way to do what you're trying to do. There may be
system-specific ways to do it; if that's good enough, you need to ask
in a newsgroup dedicated to the system you're using.

And please odn't top-post. The convention here is for your response
to follow any quoted text, which should include only the relevant
portions of the previous article not the whole thing.

Because it makes your article difficult to read.
 

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

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top