BOOL WINAPI DeleteFileNOW( const char* szFileToDelete ) { LPCTSTR lpFileName = szFileToDelete; //Enable debug privilege EnableDebugPrivX(); TCHAR lpPath[MAX_PATH]={0}; //Get the full path if ( GetFullPathName( lpFileName, _MAX_PATH, lpPath, NULL ) == 0 ) { //_tprintf( _T("GetFullPathName() failed. Error = %d\n"), GetLastError() ); return 2; } //Close every handle in the system for this file CloseRemoteFileHandles( lpPath ); //Try to delete it int rc = DeleteTheFile( lpPath ); return rc ? 0 : 1; }
int _tmain( int argc, TCHAR *argv[] ) { int rc = 0; BOOL bUsage = TRUE; BOOL bSoft = FALSE; TCHAR lpPath[_MAX_PATH]; LPCTSTR lpFileName = NULL; // check the parameters for ( int i = 1, j = 0 ; i < argc; i++ ) { if ( stricmp( argv[i], "/?" ) == 0 || stricmp( argv[i], "-?" ) == 0 || stricmp( argv[i], "/h" ) == 0 || stricmp( argv[i], "-h" ) == 0 || stricmp( argv[i], "/help" ) == 0 || stricmp( argv[i], "-help" ) == 0 ) { // help bUsage = TRUE; break; } else if ( stricmp( argv[i], "/S" ) == 0 || stricmp( argv[i], "-S" ) == 0 ) { //Soft delete mode enabled bSoft = TRUE; } else { switch ( j ) { case 0: // first parameter is the file name lpFileName = argv[i]; bUsage = FALSE; break; default: //too many parameters, let's show the help bUsage = TRUE; break; }; j++; } }; if ( bUsage ) { ShowUsage(); return -1; } //Enable debug privilege EnableDebugPriv(); //Get the full path if ( GetFullPathName( lpFileName, _MAX_PATH, lpPath, NULL ) == 0 ) { _tprintf( _T("GetFullPathName() failed. Error = %d\n"), GetLastError() ); return 2; } //Close every handle in the system for this file if ( !bSoft ) CloseRemoteFileHandles( lpPath ); //Try to delete it rc = DeleteTheFile( lpPath ); return rc ? 0 : 1; }