블로그

잠긴 파일 지우기

Code · 2008-11-05

지워지지 않는 (사용중인, 락 걸린 ) 파일 강제 삭제

* 유틸리티 UnLocker 사용
http://www.emptyloop.com/unlocker/

    - Windows 7, 64bit 에서도 제대로 작동
 - 파일 삭제 에러 0x80070780 해결

- 폴더 액세스가 거부됨, 이 작업을 수행하기 위한 권한이 필요합니다. <-- 문제 해결
- GimageX 프로그램으로 윈도우7 CD의 SOURCE폴더 안에 있는 boot.wim 파일을 풀었다가 지워지지 않을때

- 프로그램 다운로드(download)

Unlocker 1.9.2 for 32 and 64 bit - 5/16/2013

//================================================================

* 직접 만들어 보고 싶다면

origin : http://www.codeguru.com/Cpp/W-P/files/fileio/article.php/c1287/

Deleting Locked Files

Rating: http://www.codeguru.com/img/star.gifhttp://www.codeguru.com/img/star.gifhttp://www.codeguru.com/img/star.gifhttp://www.codeguru.com/img/star.gifhttp://www.codeguru.com/img/star.gif

Zoltan Csizmadia (view profile)

November 14, 2000

Environment: Windows NT4 SP6, Windows 2000

This is a command line utility to close and delete a file which is locked by another process. I doesn't work with modules.

Usage
FORCEDEL.EXE [/S] filename

/S Soft delete. Like the "del" command
filename File name you want to delete

How does it work?

Query the used file handles (system wide), and search for the processes which are using the file we want to delete.

For more information, check out the CodeGuru article entitled, Examine Information on Windows NT System Level Primitives.

Start a remote thread (CreateRemoteThread) to close the given handle in every found process (#1)

Code
The following code closes a handle in a remote process. The handle must be remote process specific. /*
Note: 1. SE_DEBUG privilege must be enabled.
2. The function works with every kind of HANDLE
3. It will bother the remote process :)
4. The handles will be invalid after you closed
them remotely
*/

//Close a handle in a remote process
DWORD CloseRemoteHandle( DWORD processID, HANDLE handle )
{
HANDLE ht = 0;
DWORD rc = 0;

_tprintf( _T("Closing handle in process #%d ... "),
processID );

// open the process
HANDLE hProcess = OpenProcess( PROCESS_CREATE_THREAD
| PROCESS_VM_OPERATION
| PROCESS_VM_WRITE
| PROCESS_VM_READ,
FALSE, processID );

if ( hProcess == NULL )
{
rc = GetLastError();
_tprintf( _T("OpenProcess() failed\n") );
return rc;
}

// load kernel32.dll
HMODULE hKernel32 = LoadLibrary( _T("kernel32.dll") );

// CreateRemoteThread()
ht = CreateRemoteThread(
hProcess,
0,
0,
(DWORD(__stdcall *)(void*))GetProcAddress(hKernel32,"CloseHandle"),
handle,
0,
&rc );

if ( ht == NULL )
{
//Something is wrong with the privileges,
//or the process doesn't like us
rc = GetLastError();
_tprintf( _T("CreateRemoteThread() failed\n") );
goto cleanup;
}

switch ( WaitForSingleObject( ht, 2000 ) )
{
case WAIT_OBJECT_0:
//Well done
rc = 0;
_tprintf( _T("Ok\n"), rc );
break;

default:
//Oooops, shouldn't be here
rc = GetLastError();
_tprintf( _T("WaitForSingleObject() failed\n") );
goto cleanup;
break;
}

cleanup:
//Closes the remote thread handle
CloseHandle( ht );

//Free up the kernel32.dll
if ( hKernel32 != NULL)
FreeLibrary( hKernel32 );

//Close the process handle
CloseHandle( hProcess );

return rc;
}

Downloads

ForceDel.zip -

알림