By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

self deleting exe

P: n/a
I have been asked to create a self deleting exe, it has been a curious
task
that has proved fruitless
I have searched in various places but to no avail

I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?

thanks in advance
dave

May 13 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On 2007-05-13 13:32, potholer wrote:
I have been asked to create a self deleting exe, it has been a curious
task
that has proved fruitless
I have searched in various places but to no avail

I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?
It really should not be that hard, but it's clearly platform specific
and as such you should as in a group for your platform, the following
might do: microsoft.public.win32.programmer

The problem I believe is that you can't delete a file while it's being
executed, so what you have to do is create a program which starts
another program (and then terminates) which deletes itself. How to do
that they can tell you in the group mentioned above.

--
Erik Wikström
May 13 '07 #2

P: n/a
Hi,

A few years back I attempted the same thing. Searching the internet however
didn't provide me with a solution the only solution I found (and the only
one that worked for me) was indeed to create a batch file. The article is
somewhere on msdn. The batch just tries to delete the executable in a loop.
The only thing left was how to get rid of the directory (without leaving
files in other places and/or making assumptions about writable directories).
Never solved that last one though.

Maybe the more modern installation packages solve the problem in a nicer way
(*.msi files). Or use one of the commercial packages (which usually 'cheats'
by having an executable in de windows dir :-) ).

Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"potholer" <dj*****@googlemail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
>I have been asked to create a self deleting exe, it has been a curious
task
that has proved fruitless
I have searched in various places but to no avail

I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?

thanks in advance
dave

May 13 '07 #3

P: n/a
potholer wrote:
I have been asked to create a self deleting exe, it has been a curious
task
that has proved fruitless
I have searched in various places but to no avail

I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?
the naive solution works only under linux:

#include <cstdio>

int main(int argc, char* argv[])
{
printf("deleting '%s'\n", argv[0]);
remove(argv[0]);
return 0;
}

and that's because in windows you can't erase a file that's currently
being executed. You should ask in a NG related to windows.

Regards,

Zeppe
May 13 '07 #4

P: n/a
potholer wrote:
>I have been asked to create a self deleting exe, it has been a curious
task
that has proved fruitless
I have searched in various places but to no avail
This is on-topic for a Win32 kernel newsgroup.

The answer is to write a .BAT file which deletes the EXE and then itself.

..BAT files evaluate as copies in memory, without locking their own file
images, so they can delete themselves.

However, this newsgroup should not cross-check my answer, because it is
off-topic. Ask again on a kernel newsgroup to verify. You can also register
a file for destruction at next boot time.

--
Phlip
http://flea.sourceforge.net/PiglegToo_1.html
May 13 '07 #5

P: n/a
On May 13, 9:36 pm, "Phlip" <phlip...@yahoo.comwrote:
potholer wrote:
I have been asked to create a self deleting exe, it has been a curious
task
that has proved fruitless
I have searched in various places but to no avail

This is on-topic for a Win32 kernel newsgroup.

The answer is to write a .BAT file which deletes the EXE and then itself.

.BAT files evaluate as copies in memory, without locking their own file
images, so they can delete themselves.

However, this newsgroup should not cross-check my answer, because it is
off-topic. Ask again on a kernel newsgroup to verify. You can also register
a file for destruction at next boot time.

--
Phlip
http://flea.sourceforge.net/PiglegToo_1.html
one way i can suggest u by which we can create a self deleting
exe.......
first get a handle of the process by
HWND FindWindow(

LPCTSTR lpClassName, // address of class name
LPCTSTR lpWindowName // address of window name
);
this function will give you the handle of the process.....
then use
LRESULT SendMessage(

HWND hwnd, // handle of destination window
UINT uMsg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
this function to close the process
in sendMessage function u can pass WM_CLOSE message
i don't it is a right way to do it...or not......
can any one suggest on this.

May 14 '07 #6

P: n/a
On May 13, 1:32 pm, potholer <djst...@googlemail.comwrote:
I have been asked to create a self deleting exe, it has been a curious
task
that has proved fruitless
I have searched in various places but to no avail

I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?
I can tell you that you can't delete process within itself
as windows maps file into process address space.
So only way to delete exe file is to start another process
from another exe, that will wait for parent to finish
then delete. Since that other exe can't be deleted
problem remains.
So solution would be to create another process from
any exe in suspended state, overwrite it's code
with one which will perform deletition, then
resume process.
Since this can't be achieved with C or C++
without relying on undefined behavior,
you asked wrong group.
Try assembler hackers ;)

Greetings, Branimir.

May 14 '07 #7

P: n/a
On May 14, 9:17 am, Branimir Maksimovic <b...@hotmail.comwrote:
On May 13, 1:32 pm, potholer <djst...@googlemail.comwrote:
I have been asked to create a self deleting exe, it has been
a curious task that has proved fruitless I have searched in
various places but to no avail
I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?
I can tell you that you can't delete process within itself
as windows maps file into process address space.
So does every other system I know which has virtual memory. The
reason it "works" under Unix is that remove() doesn't actually
delete the file, but only an entry in a directory. On most
systems (not just Windows), an entry in a directory is the file,
but in the case of Unix, it's only a pointer to the file; the
actual file is reference counted---very much like
boost::shared_ptr, in fact.
So only way to delete exe file is to start another process
from another exe, that will wait for parent to finish
then delete. Since that other exe can't be deleted
problem remains.
If the other process is a batch, the executable is something
like bash.exe, which you don't want to delete anyway. On my
installation, something like:

system( "bash -c \'sleep 5; delete me.exe'&" ) ;

works. I'm not familiar with the standard command processors
for Windows, but I would imagine that something similar would
also work.

In practice, of course, I'd probably do the reverse: start my
program from a batch script, and delete it when it is done.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 14 '07 #8

P: n/a
On May 14, 10:29 am, James Kanze <james.ka...@gmail.comwrote:
On May 14, 9:17 am, Branimir Maksimovic <b...@hotmail.comwrote:
On May 13, 1:32 pm, potholer <djst...@googlemail.comwrote:
I have been asked to create a self deleting exe, it has been
a curious task that has proved fruitless I have searched in
various places but to no avail
I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?
I can tell you that you can't delete process within itself
as windows maps file into process address space.

So does every other system I know which has virtual memory.
I didn't said that others don;t, but I see that one can
imply that that is what I thought. I couldn't say that
every system maps executable, though, because it's system
specific.

The
reason it "works" under Unix is that remove() doesn't actually
delete the file, but only an entry in a directory. On most
systems (not just Windows), an entry in a directory is the file,
but in the case of Unix, it's only a pointer to the file; the
actual file is reference counted---very much like
boost::shared_ptr, in fact.
Yes, I know. One can unlink file and it wouldn't be deleted
until last descriptor is closed.
My main platform is linux (but I'm programming for windows currently)
, started with AT&T unix, worked on solaris sparc too.
>
So only way to delete exe file is to start another process
from another exe, that will wait for parent to finish
then delete. Since that other exe can't be deleted
problem remains.

If the other process is a batch, the executable is something
like bash.exe, which you don't want to delete anyway.
I understood that OP already did that, but is interested
in doing it in different way.

Greetings, Branimir.

May 14 '07 #9

P: n/a
On 14 May, 09:59, Branimir Maksimovic <b...@hotmail.comwrote:
On May 14, 10:29 am, James Kanze <james.ka...@gmail.comwrote:
On May 14, 9:17 am, Branimir Maksimovic <b...@hotmail.comwrote:
On May 13, 1:32 pm, potholer <djst...@googlemail.comwrote:
I have been asked to create a self deleting exe, it has been
a curious task that has proved fruitless I have searched in
various places but to no avail
I can do it in vb6 using a batch file, but I have been advised it
would be better to use C or C++
does anyone know how to do this and the call it from vb6?
I can tell you that you can't delete process within itself
as windows maps file into process address space.
So does every other system I know which has virtual memory.

I didn't said that others don;t, but I see that one can
imply that that is what I thought. I couldn't say that
every system maps executable, though, because it's system
specific.

The
reason it "works" under Unix is that remove() doesn't actually
delete the file, but only an entry in a directory. On most
systems (not just Windows), an entry in a directory is the file,
but in the case of Unix, it's only a pointer to the file; the
actual file is reference counted---very much like
boost::shared_ptr, in fact.

Yes, I know. One can unlink file and it wouldn't be deleted
until last descriptor is closed.
My main platform is linux (but I'm programming for windows currently)
, started with AT&T unix, worked on solaris sparc too.
So only way to delete exe file is to start another process
from another exe, that will wait for parent to finish
then delete. Since that other exe can't be deleted
problem remains.
If the other process is a batch, the executable is something
like bash.exe, which you don't want to delete anyway.

I understood that OP already did that, but is interested
in doing it in different way.

Greetings, Branimir.
thanks to all for all your help & input

I have implemented the batch file option as it was the simplest if not
the most elegant option
and without having to resort to calling other languages

regards dave
May 14 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.