self deleting exe

P

potholer

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
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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.
 
R

Ron AF Greve

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
 
Z

Zeppe

potholer said:
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
 
P

Phlip

potholer said:
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.
 
P

Pradeep

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.

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.
 
B

Branimir Maksimovic

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.
 
J

James Kanze

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.
 
B

Branimir Maksimovic

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.
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.
 
P

potholer

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


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.





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
 

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
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top