Home All Groups Group Topic Archive Search About

a self deleting program

Author
12 May 2007 10:59 PM
caver_dave
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, if anyone can help me I
would be very grateful
thanks dave

Author
12 May 2007 11:58 PM
ajones
I'm pretty sure that you can't delete an executable while it's in use. One
way to delete it is on reboot using the MoveFileEx API and forcing a reboot.

It would be easier to shell to another program that will delete the Exe for
you and immediately end the program.

Simple:

Private Sub KillMyself()
Shell "C:\MyDeleteProgram.Exe"
End
End Sub

Your Delete Program would have one module and one sub:

Public sub Main()
    kill "C:\MyExe.Exe"
end sub


You may have to add a call to the SLEEP api to allow your original EXE to
end before you delete it.

Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds
As Long)

Public sub Main()
    sleep 2000 'play with this number till you get something that works.
    kill "C:\MyExe.Exe"
end sub

If your original exe will not always have the same name,  send a command
line to your Delete Program.

Private Sub KillMyself()
Shell "C:\MyDeleteProgram.Exe " & app.path & "\" & app.exeName & ".exe"
End

Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds
As Long)

Public sub Main()
    sleep 2000
    kill command
end sub

Show quote
"caver_dave" 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, if anyone can help me I
> would be very grateful
> thanks dave
Author
13 May 2007 12:07 AM
Bob Butler
Show quote
"ajones" <ajo***@discussions.microsoft.com> wrote in message
news:0B25E4D5-78AB-45CB-B660-6B0701A6964E@microsoft.com...
> I'm pretty sure that you can't delete an executable while it's in use. One
> way to delete it is on reboot using the MoveFileEx API and forcing a
> reboot.
>
> It would be easier to shell to another program that will delete the Exe
> for
> you and immediately end the program.
>
> Simple:
>
> Private Sub KillMyself()
> Shell "C:\MyDeleteProgram.Exe"
> End

aaaaaaaaaaaaaaaaaaaauuuuuuuuuuuuuugggggggggggggggghhhhhhhhhhhh!!!!!!!!!!!!!!!!!!
Author
13 May 2007 12:19 AM
ajones
I know. Sigh.

Show quote
"Bob Butler" wrote:

> "ajones" <ajo***@discussions.microsoft.com> wrote in message
> news:0B25E4D5-78AB-45CB-B660-6B0701A6964E@microsoft.com...
> > I'm pretty sure that you can't delete an executable while it's in use. One
> > way to delete it is on reboot using the MoveFileEx API and forcing a
> > reboot.
> >
> > It would be easier to shell to another program that will delete the Exe
> > for
> > you and immediately end the program.
> >
> > Simple:
> >
> > Private Sub KillMyself()
> > Shell "C:\MyDeleteProgram.Exe"
> > End
>
> aaaaaaaaaaaaaaaaaaaauuuuuuuuuuuuuugggggggggggggggghhhhhhhhhhhh!!!!!!!!!!!!!!!!!!
>
>
>
Author
13 May 2007 7:50 AM
Jim Carlock
"ajones" wrote...
: I know. Sigh.

LOL

@echo off
del dm.bat

A batch file can delete itself.

--
Jim Carlock
Post replies to the group.
Author
13 May 2007 12:51 AM
Steve Gerrard
Show quote
"ajones" <ajo***@discussions.microsoft.com> wrote in message
news:0B25E4D5-78AB-45CB-B660-6B0701A6964E@microsoft.com...
>
> Simple:
>
> Private Sub KillMyself()
> Shell "C:\MyDeleteProgram.Exe"
> End
> End Sub
>
> Your Delete Program would have one module and one sub:
>
> Public sub Main()
>    kill "C:\MyExe.Exe"
> end sub
>
>

Really should be
    Public Sub Main()
        Kill "C:\MyExe.Exe"
        Shell "C:\MyDeleteMyDeleteProgram.Exe"
        End
    End Sub

Ad Nauseum...
Author
13 May 2007 12:56 AM
Michael C
"caver_dave" <caverd***@discussions.microsoft.com> wrote in message
news:D143570E-AD49-4AE5-BEBD-2A53FAEB7EEB@microsoft.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, if anyone can help me I
> would be very grateful
> thanks dave

I don't think you can do this in VB. You'll need to write something in C
that will delete your VB exe and the C exe. This shouldn't be too difficult.
You'll need a retry period of a few seconds at least to allow your VB.exe to
exit.
Author
13 May 2007 1:13 AM
Steve Gerrard
"caver_dave" <caverd***@discussions.microsoft.com> wrote in message
news:D143570E-AD49-4AE5-BEBD-2A53FAEB7EEB@microsoft.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, if anyone can help me I
> would be very grateful
> thanks dave

Probably the best bet is to mark the file for deletion at reboot, using
MoveFileEx API  with the MOVEFILE_DELAY_UNTIL_REBOOT flag. It works on Win2K or
later; for pre-Win2K, you get to fumble around with WinInit.Ini. See this link
at MSDN:

http://msdn2.microsoft.com/en-us/library/aa365240.aspx
Author
13 May 2007 5:29 AM
Bob O`Bob
caver_dave 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, if anyone can help me I
> would be very grateful
> thanks dave


there will be some more groans ... I've done it,
and it *does* use the Evil End Statement:

http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/2b555c3923ec2531



    Bob
--
Author
13 May 2007 6:11 AM
Steve Gerrard
Show quote
"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
news:OYI1H$RlHHA.1820@TK2MSFTNGP04.phx.gbl...
> caver_dave 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, if anyone can help me I
>> would be very grateful
>> thanks dave
>
>
> there will be some more groans ... I've done it,
> and it *does* use the Evil End Statement:
>
> http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/2b555c3923ec2531
>
>
>
> Bob
> --

There is something deliciously brutal about that method, almost like taking a
screwdriver and scraping the program right off the hard drive. Nothing like good
old DOS, where real men can write batch files that delete themselves, no
questions asked.
Author
13 May 2007 7:53 AM
Michael C
"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
news:OYI1H$RlHHA.1820@TK2MSFTNGP04.phx.gbl...
> there will be some more groans ... I've done it,
> and it *does* use the Evil End Statement:
>
> http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/2b555c3923ec2531

There is no need to use the end statement. I presume tho you were kidding
when you posted this.

Michael
Author
13 May 2007 9:17 AM
caver_dave
Thanks to all for all your help

I think that I will try the batch file method first.

Taking the "real man" DOS method, 
then I shall be going off for a cold beer, a raw steak and a hot woman!!
though not necessarily in that order!

(miss quoted from kayak by W. Nealy deceased)

All jokes aside thanks

dave
Author
13 May 2007 10:12 AM
Michael C
"caver_dave" <caverd***@discussions.microsoft.com> wrote in message
news:6881A9EE-33BC-4CA4-8298-5BA98E0D2AAA@microsoft.com...
> Thanks to all for all your help
>
> I think that I will try the batch file method first.

Don't bother. It's a fricken terrible way to do it. Considering you've been
asked to do this I would advice against presenting this solution to whoever
ask you to do it. If I asked someone to do this and they came back with such
a solution I would be none too impressed. Doing something in C++ would be
very easy and would be the correct way to do it. If you don't know C then
ask and a C group and come back with a solution that will impress your boss.

Michael
Author
13 May 2007 12:31 PM
J French
Show quote
On Sun, 13 May 2007 20:12:34 +1000, "Michael C" <nospam@nospam.com>
wrote:

>"caver_dave" <caverd***@discussions.microsoft.com> wrote in message
>news:6881A9EE-33BC-4CA4-8298-5BA98E0D2AAA@microsoft.com...
>> Thanks to all for all your help
>>
>> I think that I will try the batch file method first.

>Don't bother. It's a fricken terrible way to do it. Considering you've been
>asked to do this I would advice against presenting this solution to whoever
>ask you to do it. If I asked someone to do this and they came back with such
>a solution I would be none too impressed. Doing something in C++ would be
>very easy and would be the correct way to do it. If you don't know C then
>ask and a C group and come back with a solution that will impress your boss.

I'm curious, why would C or CPP be able to delete a file that is
locked by the OS ?
Author
13 May 2007 12:52 PM
Michael C
"J French" <erew***@nowhere.uk> wrote in message
news:46470428.14688898@news.btopenworld.com...
> I'm curious, why would C or CPP be able to delete a file that is
> locked by the OS ?

I don't know the details but I know it can. I asked someone to do this for
me once and they did it.

Michael
Author
13 May 2007 10:06 PM
Bob O`Bob
Michael C wrote:
> "J French" <erew***@nowhere.uk> wrote in message
> news:46470428.14688898@news.btopenworld.com...
>> I'm curious, why would C or CPP be able to delete a file that is
>> locked by the OS ?
>
> I don't know the details but I know it can. I asked someone to do this for
> me once and they did it.
>



....and you didn't look inside.
Author
14 May 2007 12:43 AM
Michael C
"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
news:emD$RsalHHA.1624@TK2MSFTNGP06.phx.gbl...
>> I don't know the details but I know it can. I asked someone to do this
>> for me once and they did it.
>>
> ...and you didn't look inside.

No, my role was manager in this case.

Michael
Author
14 May 2007 9:31 AM
Dave O.
So for all you know the program COULD have spawned a batch file which first
deleted the executable and then deleted itself

Dave O.

Show quote
"Michael C" <nospam@nospam.com> wrote in message
news:%23Z$Vw$blHHA.1340@TK2MSFTNGP04.phx.gbl...
> "Bob O`Bob" <filter***@yahoogroups.com> wrote in message
> news:emD$RsalHHA.1624@TK2MSFTNGP06.phx.gbl...
>>> I don't know the details but I know it can. I asked someone to do this
>>> for me once and they did it.
>>>
>> ...and you didn't look inside.
>
> No, my role was manager in this case.
>
> Michael
>
Author
14 May 2007 12:31 PM
Michael C
"Dave O." <nob***@nowhere.com> wrote in message
news:%23u7vrqglHHA.1532@TK2MSFTNGP03.phx.gbl...
> So for all you know the program COULD have spawned a batch file which
> first deleted the executable and then deleted itself

I'd be *very* suprised if it did.

Michael
Author
13 May 2007 3:17 PM
DanS
Show quote
"Michael C" <nospam@nospam.com> wrote in
news:eRyUGcUlHHA.3928@TK2MSFTNGP02.phx.gbl:

> "caver_dave" <caverd***@discussions.microsoft.com> wrote in message
> news:6881A9EE-33BC-4CA4-8298-5BA98E0D2AAA@microsoft.com...
>> Thanks to all for all your help
>>
>> I think that I will try the batch file method first.
>
> Don't bother. It's a fricken terrible way to do it. Considering you've
> been asked to do this I would advice against presenting this solution
> to whoever ask you to do it. If I asked someone to do this and they
> came back with such a solution I would be none too impressed. Doing
> something in C++ would be very easy and would be the correct way to do
> it. If you don't know C then ask and a C group and come back with a
> solution that will impress your boss.
>
> Michael

If the bat file thing will work 100% of the time, I don't see too much
wrong with it.

The exe to do whatever is needed could write the .bat file to the user
temp directory, shell the bat file, then close. The bat file could have a
pause in it first thing to allow the exe to finish, then delete the exe
that created the bat file, then delete itself.
Author
13 May 2007 4:21 PM
Larry Serflaten
"Michael C" <nospam@nospam.com> wrote

> > I think that I will try the batch file method first.
>
> Don't bother. It's a fricken terrible way to do it. Considering you've been
> asked to do this I would advice against presenting this solution to whoever
> ask you to do it. If I asked someone to do this and they came back with such
> a solution I would be none too impressed. Doing something in C++ would be
> very easy and would be the correct way to do it. If you don't know C then
> ask and a C group and come back with a solution that will impress your boss.

Thanks for the laugh.  You  are entitled to your own opinions, but do realize
they are just that, 'your own opinions'!  If you want to impress someone, then
how about working up a solution in raw machine code, or go the OOL
approach and provide the answer in Small Talk.

You have no reservations about using the underlying programming interface
of Windows, but disdain a solution that uses the Disk Operating System?
It just seems a bit too particular to favor one, and not like the other....

By the way, how many installation packages do you know of that do not
use temporary files???

LFS
Author
14 May 2007 12:45 AM
Michael C
Show quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:%23XUXxqXlHHA.1624@TK2MSFTNGP06.phx.gbl...
> Thanks for the laugh.  You  are entitled to your own opinions, but do
> realize
> they are just that, 'your own opinions'!  If you want to impress someone,
> then
> how about working up a solution in raw machine code, or go the OOL
> approach and provide the answer in Small Talk.
>
> You have no reservations about using the underlying programming interface
> of Windows, but disdain a solution that uses the Disk Operating System?
> It just seems a bit too particular to favor one, and not like the
> other....
>
> By the way, how many installation packages do you know of that do not
> use temporary files???

You've gotta be kidding me. Surely anyone with half a brain will see that
batch file is a *very* poor solution.

Michael
Author
14 May 2007 12:46 AM
Ralph
Show quote
"Michael C" <nospam@nospam.com> wrote in message
news:%23UyWXAclHHA.1820@TK2MSFTNGP04.phx.gbl...
> "Larry Serflaten" <serfla***@usinternet.com> wrote in message
> news:%23XUXxqXlHHA.1624@TK2MSFTNGP06.phx.gbl...
> > Thanks for the laugh.  You  are entitled to your own opinions, but do
> > realize
> > they are just that, 'your own opinions'!  If you want to impress
someone,
> > then
> > how about working up a solution in raw machine code, or go the OOL
> > approach and provide the answer in Small Talk.
> >
> > You have no reservations about using the underlying programming
interface
> > of Windows, but disdain a solution that uses the Disk Operating System?
> > It just seems a bit too particular to favor one, and not like the
> > other....
> >
> > By the way, how many installation packages do you know of that do not
> > use temporary files???
>
> You've gotta be kidding me. Surely anyone with half a brain will see that
> batch file is a *very* poor solution.
>
> Michael
>

Why?

-ralph
Author
14 May 2007 1:35 AM
Michael C
"Ralph" <nt_consultin***@yahoo.com> wrote in message
news:5MydndShC9LfLNrbnZ2dnUVZ_qSrnZ2d@arkansas.net...
> Why?

Are you guys actually serious? I'm starting to suspect you're trolling. I
can understand using a dos command if it is an *absolute* last resort but in
this case there is an easy way around it. I remember saying recently that if
I got on a newsgroup and said the world was round someone say it was flat.
No matter how far out an idea there is always someone arguing it. Doesn't
this thing have your hack-o-metre (tm) going off the gauge?

Anyway, in answer to your question, it has no timeout, hence no error
warning, permissions might deny running a bat file. If it fails it will sit
on 100% cpu forever and cause problems shutting down. If we need to add
functionality we will be restricted to batch file commands hence it is
inflexible. But the real reason for not doing this is that it just feels
wrong. When something feels wrong there are more than likely unforseen
issues that will arise at a later date. As an example, we might fun this on
our dev machine and get no problems, release it and think everything is all
fine and dandy. But then the customer's virus scanner picks up on this and
interferes with the process somehow. It might warn that a program is
exhibiting virus like behaviour, which the customer will not enjoy. It might
deny the batch file altogether, still with a warning. It might allow the
batch file but deny the delete. Anything could happen.

I'm sure you'll reply with fixes for some of the above problems, but please
don't bother if you can't fix all of them.

I don't see what the issue is with using C. The wizard will create a blank
project for you and you just need to insert the appropriate API call to
delete the file and maybe one include statement and a loop that times out
after x seconds. Very simple stuff and then it has been done properly.

Michael
Author
14 May 2007 2:33 AM
Steve Gerrard
"Michael C" <nospam@nospam.com> wrote in message
news:ebnEhcclHHA.1388@TK2MSFTNGP05.phx.gbl...
> "Ralph" <nt_consultin***@yahoo.com> wrote in message
> news:5MydndShC9LfLNrbnZ2dnUVZ_qSrnZ2d@arkansas.net...
>> Why?
>
>
> I don't see what the issue is with using C. The wizard will create a blank
> project for you and you just need to insert the appropriate API call to delete
> the file and maybe one include statement and a loop that times out after x
> seconds. Very simple stuff and then it has been done properly.
>

Do you think this C program will be able to delete itself while making the API
call? Or are you just talking about deleting the main program file? If the
latter, the issue then becomes, how do you delete the C program, etc. Have a
look at the link in Tony Proctor's post in this thread.
Author
14 May 2007 3:35 AM
Michael C
"Steve Gerrard" <mynameh***@comcast.net> wrote in message
news:EO-dnQyhf5b_V9rbnZ2dnUVZ_jKdnZ2d@comcast.com...
> Do you think this C program will be able to delete itself while making the
> API call? Or are you just talking about deleting the main program file? If
> the latter, the issue then becomes, how do you delete the C program, etc.
> Have a look at the link in Tony Proctor's post in this thread.

I'm not sure how it was done but it did get done.

Michael
Author
14 May 2007 3:38 AM
Michael C
"Steve Gerrard" <mynameh***@comcast.net> wrote in message
news:EO-dnQyhf5b_V9rbnZ2dnUVZ_jKdnZ2d@comcast.com...
> Do you think this C program will be able to delete itself while making the
> API call? Or are you just talking about deleting the main program file? If
> the latter, the issue then becomes, how do you delete the C program, etc.
> Have a look at the link in Tony Proctor's post in this thread.

You could be right that it was not as easy as I suggested. I asked someone
to write me something in C that would delete an exe. They did it in fairly
quick time and didn't mention any issues so I assumed it was easy.

Michael
Author
14 May 2007 3:33 AM
Robert Morley
> I don't see what the issue is with using C.

The obvious response to this is that the OP may not have anything to compile
C with.  I don't!

That said, I gotta go with you on the rest of the post (which I've
snipped)...having to resort to a DOS batch file just screams of hack to me,
and I'd avoid it unless there were no other way.



Rob
Author
14 May 2007 7:19 AM
Larry Serflaten
"Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote
> > I don't see what the issue is with using C.
>
> The obvious response to this is that the OP may not have anything to compile
> C with.  I don't!
>
> That said, I gotta go with you on the rest of the post (which I've
> snipped)...having to resort to a DOS batch file just screams of hack to me,
> and I'd avoid it unless there were no other way.


What about shelling out to the command line interpreter?  There are hundreds
of posts where the solution includes a call to COMSPEC to do this or that.
Its the same mechanism, except the batch file allows for additional commands!

As far as I am concerned, if a simple method works where you need it to work,
then it is the right solution....

LFS
Author
14 May 2007 7:36 AM
Michael C
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:uilIkgflHHA.3512@TK2MSFTNGP06.phx.gbl...
> What about shelling out to the command line interpreter?  There are
> hundreds
> of posts where the solution includes a call to COMSPEC to do this or that.
> Its the same mechanism, except the batch file allows for additional
> commands!
>
> As far as I am concerned, if a simple method works where you need it to
> work,
> then it is the right solution....

Except this solution is likely not to work.

Michael
Author
15 May 2007 1:19 AM
Robert Morley
> What about shelling out to the command line interpreter?  There are
> hundreds
> of posts where the solution includes a call to COMSPEC to do this or that.
> Its the same mechanism, except the batch file allows for additional
> commands!
>
> As far as I am concerned, if a simple method works where you need it to
> work,
> then it is the right solution....

It's the fact that you're using the shell that I have problems with, not the
fact that you're calling a batch file.  There are times when it's necessary,
but I agree with Michael (which doesn't happen often)...using the shell, no
matter how you're calling it, should be avoided unless there's simply no
other way, or the other way would require an inordinate amount of effort.
In this case, most of the alternate methods DO require an inordinate amount
of effort, so you might be best to go with the batch file, but as a rule, I
consider that a last resort, not a first one.

To each his own, though...I'm not here to dictate to anybody how they should
program. :-)



Rob
Author
15 May 2007 1:44 AM
youare
On Mon, 14 May 2007 21:19:39 -0400, "Robert Morley"
<rmor***@magma.ca.N0.Freak1n.sparn> wrote:
in <uzQQp8olHHA.4***@TK2MSFTNGP05.phx.gbl>

Show quote
>> What about shelling out to the command line interpreter?  There are
>> hundreds
>> of posts where the solution includes a call to COMSPEC to do this or that.
>> Its the same mechanism, except the batch file allows for additional
>> commands!
>>
>> As far as I am concerned, if a simple method works where you need it to
>> work,
>> then it is the right solution....
>
>It's the fact that you're using the shell that I have problems with, not the
>fact that you're calling a batch file.  There are times when it's necessary,
>but I agree with Michael (which doesn't happen often)...using the shell, no
>matter how you're calling it, should be avoided unless there's simply no
>other way, or the other way would require an inordinate amount of effort.
>In this case, most of the alternate methods DO require an inordinate amount
>of effort, so you might be best to go with the batch file, but as a rule, I
>consider that a last resort, not a first one.
>
>To each his own, though...I'm not here to dictate to anybody how they should
>program. :-)
>
>
>
>Rob
>

To me, whatever works works.  And any argument regarding technique is
ridiculous.
Frank
Author
15 May 2007 2:02 AM
Michael C
<youare@kidding.right> wrote in message
news:d04i43llmkfmeqmr7bs0vi7fpcqqsgm6ca@4ax.com...
> To me, whatever works works.

Except this technique is *very* likely to fail.

> And any argument regarding technique is
> ridiculous.

This is one of those things that comes back and bites you later. As a one
off it's easy to fix if it does but if an app gets full of hacks like this
(and don't think this is anything other than a hack) then it becomes
difficult to maintain.

This bat file is also very limited, something as simple as showing a
messagebox if it fails is not possible.

Michael
Author
15 May 2007 2:25 AM
youare
On Tue, 15 May 2007 12:02:07 +1000, "Michael C" <nospam@nospam.com>
wrote:
in <#Ifr$PplHHA.4***@TK2MSFTNGP04.phx.gbl>

Show quote
><youare@kidding.right> wrote in message
>news:d04i43llmkfmeqmr7bs0vi7fpcqqsgm6ca@4ax.com...
>> To me, whatever works works.
>
>Except this technique is *very* likely to fail.
>This is one of those things that comes back and bites you later. As a one
>off it's easy to fix if it does but if an app gets full of hacks like this
>(and don't think this is anything other than a hack) then it becomes
>difficult to maintain.
>
>This bat file is also very limited, something as simple as showing a
>messagebox if it fails is not possible.
>
>Michael


Bite me.
Frank
Author
14 May 2007 7:41 AM
J French
On Mon, 14 May 2007 11:35:27 +1000, "Michael C" <nospam@nospam.com>
wrote:

<snip>

>I don't see what the issue is with using C. The wizard will create a blank
>project for you and you just need to insert the appropriate API call to
>delete the file and maybe one include statement and a loop that times out
>after x seconds. Very simple stuff and then it has been done properly.

What API call ?

There are not many things that C can do that VB can't
(except for device drivers)
Author
14 May 2007 9:35 AM
Michael C
"J French" <erew***@nowhere.uk> wrote in message
news:464811dd.2180060@news.btopenworld.com...
> What API call ?

I'm not sure of the exact implementation.

> There are not many things that C can do that VB can't
> (except for device drivers)

There's PLENTY that C can do that VB can't. VB can only do windows apps and
dlls that run on windows. C can do pretty much anything. I've written
embedded stuff for 8 bit processors in C.

Michael
Author
14 May 2007 7:54 PM
Karl E. Peterson
Michael C <nospam@nospam.com> wrote:
> You've gotta be kidding me. Surely anyone with half a brain will see that
> batch file is a *very* poor solution.

As opposed to those of us with a wholly intact brain, eh?
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
13 May 2007 8:23 PM
Tony Proctor
Here's an article that discusses the general issue:
http://www.catch22.net/tuts/selfdel.asp. It contains a comprehensive
explanation of the problem, and some very interesting "solutions"

    Tony Proctor

Show quote
"caver_dave" <caverd***@discussions.microsoft.com> wrote in message
news:D143570E-AD49-4AE5-BEBD-2A53FAEB7EEB@microsoft.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, if anyone can help me I
> would be very grateful
> thanks dave
Author
13 May 2007 9:01 PM
Mike Williams
"Tony Proctor" <tony_proctor@aimtechnology_NoMoreSPAM_.com> wrote in message
news:%236$QKyZlHHA.5024@TK2MSFTNGP06.phx.gbl...

> Here's an article that discusses the general issue:
> http://www.catch22.net/tuts/selfdel.asp. It contains a comprehensive
> explanation of the problem, and some very interesting "solutions"

That's a very interesting read, Tony. A much better read than Michael C's
statement informing us that one of the methods previously mentioned in this
thread (and also mentioned in the link you posted) was "a frecken terrible
way to do it" and informing us of the fact that it is very easy to do in C++
but, apparently, according to his later response, not quite so easy that
Michael C actually knows how to do it himself ;-)

No wonder he doesn't call himself Michael C++ ;-)

Mike
Author
14 May 2007 8:04 AM
J French
On Sun, 13 May 2007 21:23:14 +0100, "Tony Proctor"
<tony_proctor@aimtechnology_NoMoreSPAM_.com> wrote:

>Here's an article that discusses the general issue:
>http://www.catch22.net/tuts/selfdel.asp. It contains a comprehensive
>explanation of the problem, and some very interesting "solutions"

An interesting read
- it looks a little hairy to say the least

I've just done a test using Basic 7.1 and an exe can delete itself
- I expect this would upset anti virus systems
Author
14 May 2007 2:05 PM
caver_dave
Blimey talk about proliferation !
Thanks to all

I have looked into both vb & c solutions and have found solutions in both.

I have gone with the batch file as out of all of them it is the simplest and
does not involve me  rewiring my brain to work with C / Cpp.

To Mike C
my boss does not know any dos and very little vb and was quite impressed
that a bog standard GUI designer could do it.

Once again thanks guys
dave
Author
15 May 2007 12:07 AM
Michael C
Show quote
"caver_dave" <caverd***@discussions.microsoft.com> wrote in message
news:5C51C6F7-AC76-4528-ADF6-DB9409D4934E@microsoft.com...
> Blimey talk about proliferation !
> Thanks to all
>
> I have looked into both vb & c solutions and have found solutions in both.
>
> I have gone with the batch file as out of all of them it is the simplest
> and
> does not involve me  rewiring my brain to work with C / Cpp.
>
> To Mike C
> my boss does not know any dos and very little vb and was quite impressed
> that a bog standard GUI designer could do it.

Even after all the potential issues that I listed you still went with this
"solution"?!? And your boss was impressed?!? Notice that not one single
person listed a workaround for any of the problems I listed.

Michael
Author
15 May 2007 1:40 AM
Robert Morley
> Even after all the potential issues that I listed you still went with this
> "solution"?!? And your boss was impressed?!? Notice that not one single
> person listed a workaround for any of the problems I listed.

Even though I'm with you 100% on this one, I think you're exaggerating the
flaws with a batch file.  Here's your comments repeated, and my comments on
them.

> If it fails it will sit on 100% cpu forever and cause problems shutting
> down.

Why would a "del" fail and then sit in a busy loop?  Assuming the batch file
is on a local drive, if it fails in such a way that it busy loops, it's
probably cuz your drive is failing, in which case a stuck batch file is
going to be the least of your problems.

> If we need to add functionality we will be restricted to batch file
> commands hence it is inflexible.

If you need added functionality, that can be addressed in an executable
file; the only purpose of the batch file is to delete the exe once all other
tasks are completed.  If you need functionality afterwards, you spawn
another executable, which you can then cause to self-delete in the same way.
I don't see this as an issue.

> But the real reason for not doing this is that it just feels wrong.

While I agree, I also think that using Exit Do or Exit For "feels wrong",
and you will never see those constructs in any program I've written.  That
doesn't mean that it's necessarily a bad thing for someone else who doesn't
have my structured programming prejudices.

> It might warn that a program is exhibiting virus like behaviour, which the
> customer will not enjoy. It might deny the batch file altogether, still
> with a warning. It might allow the batch file but deny the delete.
> Anything could happen.

Ummm...on-site testing wouldn't tell you about this problem?

> I'm sure you'll reply with fixes for some of the above problems, but
> please don't bother if you can't fix all of them.

I didn't "fix" a single one of them, but I did give reasons why they might
not be issues for someone.  Does that count?

> I don't see what the issue is with using C. The wizard will create a blank
> project for you and you just need to insert the appropriate API call to
> delete the file and maybe one include statement and a loop that times out
> after x seconds. Very simple stuff and then it has been done properly.

As already discussed elsewhere in the thread, there is no appropriate API
call, so another solution needs to be found; C doesn't help with this,
unless you count the fact that you can use inline assembly (as documented on
the website someone linked to).



Rob
Author
15 May 2007 2:07 AM
Steve Gerrard
"Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote in message
news:%23pmZVKplHHA.3484@TK2MSFTNGP02.phx.gbl...

>> If it fails it will sit on 100% cpu forever and cause problems shutting down.
>

If it does fail, you can just delete it while it is still running, since it is a
batch file! :)


>> It might warn that a program is exhibiting virus like behaviour, which the
>> customer will not enjoy. It might deny the batch file altogether, still with
>> a warning. It might allow the batch file but deny the delete. Anything could
>> happen.
>

And this could never happen with any other kind of program except a batch file?
:)


As I said in another post, I like the raw brutality of that batch file.

In the real world, I don't see much need for a self-deleting exe in the first
place. I say go with

Private Sub Command1_Click()
Shell "rundll32.exe shell32.dll," _
    & "Control_RunDLL appwiz.cpl", _
    vbNormalFocus
Unload Me
End Sub

which just takes the user to Add or Remove Programs :)
Author
15 May 2007 1:55 AM
Larry Serflaten
"Michael C" <nospam@nospam.com> wrote


> Even after all the potential issues that I listed you still went with this
> "solution"?!? And your boss was impressed?!? Notice that not one single
> person listed a workaround for any of the problems I listed.

If it needs to delete a file, then it has to have permissions to do so.  That is
a given and has to be set up as a condition of installation.  After that, how
could it fail?

LFS
Author
15 May 2007 2:14 AM
Ralph
Show quote
"Michael C" <nospam@nospam.com> wrote in message
news:O7FI2PolHHA.1216@TK2MSFTNGP03.phx.gbl...
> "caver_dave" <caverd***@discussions.microsoft.com> wrote in message
> news:5C51C6F7-AC76-4528-ADF6-DB9409D4934E@microsoft.com...
> > Blimey talk about proliferation !
> > Thanks to all
> >
> > I have looked into both vb & c solutions and have found solutions in
both.
> >
> > I have gone with the batch file as out of all of them it is the simplest
> > and
> > does not involve me  rewiring my brain to work with C / Cpp.
> >
> > To Mike C
> > my boss does not know any dos and very little vb and was quite impressed
> > that a bog standard GUI designer could do it.
>
> Even after all the potential issues that I listed you still went with this
> "solution"?!? And your boss was impressed?!? Notice that not one single
> person listed a workaround for any of the problems I listed.
>
> Michael
>

I'm with Larry, I didn't see it as being that big of a problem, but was
curious why you did. I asked for an explanation, and you gave it. While I
can understand some of your concerns, I still don't see it as a 'bad
solution', if it works.

My guess no one bothered to reply with a 'workaround' because in practical
use - none is needed.

"... it has no timeout, hence no error warning"
I don't see that as problem because who would it report the timeout or error
to? And what would the program do when it received an error? I can't think
of any process that wouldn't have an opportunity to fail - given the right
circumstances.

"...  permissions might deny running a bat file."
More possible for a .bat or .com file than a .exe perhaps. If the
environment is unfriendly, its just unfriendly. Can happen to anyone.

"If it fails it will sit on 100% cpu forever and cause problems shutting
down." I doubt that - all its doing is deleting a file, if it fails it
fails. if it hangs it hangs. Windows shutdown is very good at killing off
unresponsive apps. But again, it might happen to any process.

"If we need to add functionality we will be restricted to batch file
commands hence it is inflexible."
What functionality? It is attempting to delete a file.

"But the real reason for not doing this is that it just feels wrong."
It doesn't fell that wrong to me, assuming it works. Howerver, I'm not that
convinced it will.

As for the rest of your points, upsetting virus-checkers, etc. That's the
risk you would run with any solution, except...

IMHO, I prefer Steve's suggestion. Sometimes we get too cute - Windows
offers this kind of service - why not just use it.

-ralph

AddThis Social Bookmark Button