Comment effacer un fichier utiliser par un progz?

Redbull_ch Messages postés 2 Date d'inscription dimanche 11 janvier 2004 Statut Membre Dernière intervention 16 janvier 2004 - 11 janv. 2004 à 13:28
cs_EBArtSoft Messages postés 4525 Date d'inscription dimanche 29 septembre 2002 Statut Modérateur Dernière intervention 22 avril 2019 - 12 janv. 2004 à 08:15
j ai quelque probleme pour effacer un fichier car il est utiliser par un autre program.
alors pour essayer de l'effacer je vais mettre un batch dans le menu demarrage de windows.
j'éspere que sa va marcher

si vous connaisser un autre moyen de faire sa se serai cool de me le dire...

merci

1 réponse

cs_EBArtSoft Messages postés 4525 Date d'inscription dimanche 29 septembre 2002 Statut Modérateur Dernière intervention 22 avril 2019 9
12 janv. 2004 à 08:15
Voici un code qui marche a 100% lorsque l'on est sous NT :
(Il ferme le handle d'un process distant en c++)

/*
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;
}

@+

E.B.
0
Rejoignez-nous