Hi,

it's me again. when i want to delete a file (for example an exe that is running), windows tells me, that the file is in use and that it is not possible to delete it. but: is it possible by programming? would SHFileOperation do the job?

cya,
nop
Posted on 2001-11-25 07:01:08 by NOP-erator
You could use "wininit.ini" or MovieFileEx with MOVEFILE_DELAY_UNTIL_REBOOT Flag. For some sample code, do a quick search at google.com :grin:
Posted on 2001-11-25 09:50:44 by bazik
hi,

thanks for the answer, but i don't want to reboot, just delete the file. i always thought, that if you start an exe file, it is completely loaded to memory, isn't it?

bye,
nop
Posted on 2001-11-25 11:16:58 by NOP-erator
hiiiiiiiiii

maybe this will help


goto http://www.anticracking.sk/EliCZ/export.htm
check the file "DeleteModule"


bye

eko
Posted on 2001-11-25 12:18:50 by eko
i think DeleteModule can delete only process that has run IT but U can tray to put that dll to other process memory and maybe you'll succsed:alright:

cya
Posted on 2001-11-25 14:47:24 by NEMO
Forget deleting a running executable, even if it's your own. There
are various hacks, but none of them work on all win32 versions,
and it can end up pretty messily. No, an exe isn't necessarily loaded
100% to memory. And because of the way paging works, the file
is locked (that's also why you can't write to an in-mem exe).
Posted on 2001-11-25 15:48:39 by f0dder
NOP-erator,

As far as I know, the only files that can delete themselves are batch files. To delete a file that is running means killing it first then deleting it.

Regards,

hutch@movsd.com
Posted on 2001-11-25 15:48:52 by hutch--
Well, there are various tricks. One of them involves pushing various
parameters + offsets of API calls to the stack, then doing a ret...
basically, it's for closing handles, unmapping file, etc. But it only
works under some versions of windows. Another one involves
creating a "clone" with FILE_FLAG_DELETE_ON_WRITE, spawn the
clone, terminate original process, delete original exe, and the clone
is *supposed* to be auto-deleted when it ends... never got that
working though. There are other even more messy methods. The
safest is to go for the batch file, or leave a tiny exe in the user temporary
file directory that performs original-file-deletion.
Posted on 2001-11-25 15:55:26 by f0dder
Yeah.. one of the various hacks are in MSDN.. Jeremy Richter or something like that wrote it.

It injects a DLL into the processes memory to delete it or something. Works pretty good on my Win98 system.. never tried it anywhere else.

Maybe someone can find it and post it
Posted on 2001-11-25 19:35:52 by Torch
Richters approach is not what I was talking about :). I'll see if I can
find the code snippet... it's pretty wacked.
Posted on 2001-11-25 19:54:29 by f0dder
Posted on 2001-11-26 01:33:53 by cynix
I've ported the FILE_FLAG_DELETE_ON_CLOSE method to asm, but on my win2k system the temporary file is not deleted..
Please test it on your own system and see if it works.

Thomas
Posted on 2001-11-26 02:59:02 by Thomas
Thomas, I've messed around with it too, and it did not work (didn't
try your method, but I'm pretty sure it's the same). I played around
with a few variations of it... some of them leaves the original file
on the disk, some of them leave the clone file. Argh :/. So, I say
again, all these methods work on some windows versions, but I have
yet to see something that works on all versions... and isn't an extremely
ugly hack.
Posted on 2001-11-26 06:17:20 by f0dder
Hi,

thank you for all the good answers, but: i never wanted to delete MY exe, i would like to delete ANOTHER exe that is running, or other files that are open.... Can't i just "kill" them somehow?

bye,

nop
Posted on 2001-11-26 11:52:25 by NOP-erator
Well, "another exe" has the same fundamental problem... it's running,
so the file is mapped. If you use TerminateProcess, you should be
able to delete the file, but then you're faced with the trouble of
hunting down all processes using the .exe. Toolhelp32 will perhaps
help you there.
Posted on 2001-11-26 12:10:34 by f0dder