473,379 Members | 1,530 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,379 software developers and data experts.

self deleting exe

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
9 8294
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
15
by: Rick | last post by:
Hi, Does deleting an object more than one times incur undefined behavior? I think it doesn't but just making sure... thanks Rick
11
by: Laszlo Zsolt Nagy | last post by:
Hello, Do you know how to implement a really efficient self reordering list in Python? (List with a maximum length. When an item is processed, it becomes the first element in the list.) I would...
28
by: ROSY | last post by:
1.How to make self deletable .exe file such that during runtime the file delete itself from the current path. plz answer, thanks in advence. bye.
4
by: al havrilla | last post by:
hi all what does the phrase: "scalar deleting destructor" mean? i'm getting this in a debug error message using c++ 7.1 thanks Al
6
by: Jason Shohet | last post by:
Is there a way for a code-behind to delete the dll after an expiration, or if a user doesn't enter the right password. ie, lets say i license something to someone for 3 months. After that time,...
6
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application...
3
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents,...
8
by: kvt | last post by:
Hi, One of my friend puzzled me to write a program which destructs itself. i.e, by the time it stops execution, its executable file should be deleted. I tried a lot like a) using " system()...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.