Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2005, 06:17
tAz
 
Posts: n/a
Deleting a file in use without rebooting

Anybody knows how to programatically delete a file currently in use without resorting to deleting it on the next reboot?

One idea is to enumerate all open handles of all processes and force them to close the handle to your target file, then deleting it afterwards. Unfortunately, it's too messy.

I'm looking for some undocumented or easier way to do this. Anyone?
Reply With Quote
  #2  
Old 04-06-2005, 07:47
kaos_xlro
 
Posts: n/a
Well, I know a way but dont know how much messy its to you:

1. Click Start > Run > type in taskman > OK, this will open a task manager
2. Look in process "explorer.exe", and finish the task, without closing the task manager
3. In the task manager click on File > New Task(Run) > type in cmd > OK
4. Go to the command line interface, find the file and delete it.
5. Go back to the Windows Task Manager, click File > select New Task (Run) > type in explorer.exe > click OK. And you should be back into explorer and without the file.

Now to do it programmatically you can improve this way in a batch file (I mean .bat)
Reply With Quote
  #3  
Old 04-06-2005, 09:27
thewhiz
 
Posts: n/a
#include <windows.h>

int main(int argc, char **argv)
{
HMODULE module = GetModuleHandle(0);
CHAR buf[MAX_PATH];

GetModuleFileName(module, buf, sizeof(buf));
CloseHandle(HANDLE(4));

__asm {
lea eax, buf
push 0
push 0
push eax
push ExitProcess
push module
push DeleteFile
push UnmapViewOfFile
ret
}

return 0;
}

----------------------------------------------------
Something like this may do what you are wanting with some modifications. Caveat, I have used this for self-deleting executables as they run in memory.

Last edited by thewhiz; 04-06-2005 at 10:22.
Reply With Quote
  #4  
Old 04-06-2005, 14:01
xobor xobor is offline
Friend
 
Join Date: May 2002
Location: Slovakia
Posts: 115
Rept. Given: 6
Rept. Rcvd 4 Times in 4 Posts
Thanks Given: 2
Thanks Rcvd at 19 Times in 14 Posts
xobor Reputation: 5
Shub-Nigurrath has released his ForceDel with sources sometimes ago , maybe it can helps

regards
Reply With Quote
  #5  
Old 04-06-2005, 14:21
surferxyz surferxyz is offline
Friend
 
Join Date: Jan 2005
Location: Planet Earth
Posts: 73
Rept. Given: 0
Rept. Rcvd 9 Times in 4 Posts
Thanks Given: 10
Thanks Rcvd at 52 Times in 19 Posts
surferxyz Reputation: 9
Can you help
*http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/inuse-o.asp
Reply With Quote
  #6  
Old 04-06-2005, 22:23
MaRKuS-DJM's Avatar
MaRKuS-DJM MaRKuS-DJM is offline
Cracker + Unpacker
 
Join Date: Aug 2003
Location: Virtual World / Network
Posts: 553
Rept. Given: 7
Rept. Rcvd 6 Times in 4 Posts
Thanks Given: 3
Thanks Rcvd at 16 Times in 10 Posts
MaRKuS-DJM Reputation: 6
you can also use process explorer by sysinternals, it can close handles... if it is a loaded dll you can try the prog called "undll"
Reply With Quote
  #7  
Old 04-07-2005, 19:03
amigo amigo is offline
Friend
 
Join Date: Dec 2002
Posts: 30
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
amigo Reputation: 0
Some years ago I' ve written small program for win 95 /98 /[maybe Me].
It was a dynamically loaded vxd which enabled deleting working files, including working programs. The main patch of the system was in VFAT.vxd, and the other two patches in shell32.dll.
When vxd is loaded, there are no limitations in file sharing - for example it is possible to delete all files on system drive under working Windows .
Windows DON'T HANG of course, because necessary ring3 and ring0 files are loaded in RAM so the files on disk are not necessary. Only strange "sharing files" rules in Windows are responsible for not-permitted deleting of working programs or exclusively open files. There are not "internal" or "systemic" causes for this.
So, it's possible to delete all open files under 9x after patching virtual FAT, WITHOUT closing handles.
I'm sure it's possible under NTFS, when I'll have more time may be I'll look for proper patch in (probably) NTFS.sys .
Regards
amigo
Reply With Quote
  #8  
Old 04-09-2005, 05:43
tAz
 
Posts: n/a
Quote:
Originally Posted by xobor
Shub-Nigurrath has released his ForceDel with sources sometimes ago , maybe it can helps
thanks for the info xobor. i tried to search for forcedel, and found it. unfortunately, it uses the same technique i described in my initial post.
Reply With Quote
  #9  
Old 04-09-2005, 05:47
tAz
 
Posts: n/a
Quote:
Originally Posted by amigo
Some years ago I' ve written small program for win 95 /98 /[maybe Me].
It was a dynamically loaded vxd which enabled deleting working files, including working programs. The main patch of the system was in VFAT.vxd, and the other two patches in shell32.dll.
When vxd is loaded, there are no limitations in file sharing - for example it is possible to delete all files on system drive under working Windows .
Windows DON'T HANG of course, because necessary ring3 and ring0 files are loaded in RAM so the files on disk are not necessary. Only strange "sharing files" rules in Windows are responsible for not-permitted deleting of working programs or exclusively open files. There are not "internal" or "systemic" causes for this.
So, it's possible to delete all open files under 9x after patching virtual FAT, WITHOUT closing handles.
I'm sure it's possible under NTFS, when I'll have more time may be I'll look for proper patch in (probably) NTFS.sys .
Regards
amigo
this seems dangerous! i just want someway to clear the handle count of a file in a windows system so that it'll permit a DeleteFile call.
something like finding the structure containing the handle counts and the file they point to, and setting it to zero (meaning no one's using the file), so i can delete it. anyone ever done this before?
Reply With Quote
  #10  
Old 04-09-2005, 17:31
Shub-Nigurrath's Avatar
Shub-Nigurrath Shub-Nigurrath is offline
VIP
 
Join Date: Mar 2004
Location: Obscure Kadath
Posts: 919
Rept. Given: 60
Rept. Rcvd 419 Times in 94 Posts
Thanks Given: 68
Thanks Rcvd at 330 Times in 100 Posts
Shub-Nigurrath Reputation: 400-499 Shub-Nigurrath Reputation: 400-499 Shub-Nigurrath Reputation: 400-499 Shub-Nigurrath Reputation: 400-499 Shub-Nigurrath Reputation: 400-499
the forcedel suggested ad the beginning exactly does this before deleting a file..you can also with an option to only close or list all the open handle of a file
__________________
Ŝħůb-Ňìĝùŕřaŧħ ₪)
There are only 10 types of people in the world: Those who understand binary, and those who don't
http://www.accessroot.com
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Media Descriptor File (MDF/MDS) file format NimDa2k General Discussion 0 03-22-2009 16:49
Softice rebooting my machine Mok General Discussion 4 09-07-2003 00:01


All times are GMT +8. The time now is 14:43.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )