Ejemplo n.º 1
0
bool CFileControlTool::RemoveFile(LPCTSTR lpFileName,bool bForce /* = false */)
{
	TCHAR szFullPathName[_MAX_PATH];  
	BOOL bRet = FALSE;

	//Enable debug privilege   
	EnableDebugPriv();   

	//Get the full path  
	
	if ( GetFullPathName( lpFileName, _MAX_PATH, szFullPathName, NULL ) == 0 )   
	{   
		Out(Dbg,_T("RemoveFile Failed. Error = %d\n"),GetLastError());   
		return FALSE;   
	}   
	

	//Close every handle in the system for this file   
	if (bForce) 
		bRet = CloseRemoteFileHandles(szFullPathName); 
	else
		bRet = DeleteFile(szFullPathName); 

	return bRet;   
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
bool CFileControlTool::RenameFile(LPCTSTR lpFileName,LPCTSTR lpNewFileName,bool bForce /* = false */)
{
	TCHAR szFullPathName[_MAX_PATH];  
	BOOL bRet = FALSE;

	//Enable debug privilege   
	EnableDebugPriv();   

	//Get the full path
	if (GetFullPathName(lpFileName,MAX_PATH,szFullPathName,NULL) == 0)   
	{   
		Out(Dbg,_T("RemoveFile Failed. Error = %d\n"),GetLastError());   
		return FALSE;   
	}

	//Close every handle in the system for this file   
	if (bForce) 
		bRet = CloseRemoteFileHandles(szFullPathName); 
	
	bRet = ::MoveFileEx(szFullPathName,lpNewFileName,MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED); 

	return bRet;   
}
Ejemplo n.º 4
0
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;
}