Thread: Delete files that are used

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    Delete files that are used

    Hi.
    I know that you can delete files with Delete ( "Path\\File_Name" );
    but i doesn't delete files when they are used, is there anyway to delete files anyway?
    Thanks Yuri.

  2. #2
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Quote Originally Posted by Yuri
    Hi.
    I know that you can delete files with Delete ( "Path\\File_Name" );
    but i doesn't delete files when they are used, is there anyway to delete files anyway?
    Thanks Yuri.
    Oddly enough I heard it is possible. There was an example on the mYg0t forums, but now it's gone.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    36
    Actually, the post on the myg0t forums are still there. Here's the code:
    Code:
    bool newDeleteFile(LPCSTR lpFileName)
    {
    	OBJECT_ATTRIBUTES pObj;
    	UNICODE_STRING uFile;
    	WCHAR wFile[256];
    
    	// create an UNICODE path
    	swprintf(wFile, L"\\??\\%S", lpFileName);
    
    	// create UNICODE_STRING	
    	pRtlInitUnicodeString(&uFile, wFile);
    
    	// setup OBJECT_ATTRIBUTES for NtDeleteFile
    	InitializeObjectAttributes(&pObj, &uFile, OBJ_CASE_INSENSITIVE, NULL, NULL);
    	if(NT_SUCCESS(pNtDeleteFile(&pObj)))
    		return true;
    
    	return false;
    }
    "This can be useful to get rid of trojan files and folders even if the trojan is running or any of the files are in use.
    I will post the rest of the code necessary to use that function later along with more info about all of it.

    Credits: NT Internals, MSDN, and the DDK

    This may not appear elsewhere without permission, but may be linked to."
    (oh well guess i broke that rule, but too bad)

  4. #4
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Thanks for the code but Im a bit new to C++ so could you maybe explain the code? Cause I can't see where I should enter the path and file name of the file I want to delete.

  5. #5
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    If I try to compile it, even when I don't know how this works, I get like 100 compile errors. For example:
    Code:
    `OBJECT_ATTRIBUTES' undeclared (first use this function)
     expected `;' before "pObj" 
    `UNICODE_STRING' undeclared (first use this function) 
    expected `;' before "uFile" 
    `uFile' undeclared (first use this function) 
     `pRtlInitUnicodeString' undeclared (first use this function) 
    `pObj' undeclared (first use this function) 
    `OBJ_CASE_INSENSITIVE' undeclared (first use this function)
    `InitializeObjectAttributes' undeclared (first use this function) 
    `pNtDeleteFile' undeclared (first use this function)
    `NT_SUCCESS' undeclared (first use this function)
    Please help, I really could use it.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    you have to include windows.h

  7. #7
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    I have included windows.h, .

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    then post your program, and what compiler you are using. You might also have to define _UNICODE somewhere
    Last edited by Ancient Dragon; 10-18-2005 at 12:30 PM.

  9. #9
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Ok, here is the code, it may be big but you there are just a view pieces that don't work. Oh yeah, I use Dev-C++ compiler.

    Code:
    #include <iostream>
    #include <windows.h>
    #include <fstream>
    
    using namespace std;
    
    string ALLP1 = "\n[AGP_Interface.AAGUIController]\n";
    string ALLP2 = "AutoLoad=(MenuClassName=\"";
    string ALLP3 = "\",bPreInitialize=True)\n";
    
    string Caption = "Bot Loader v1.0 by Pvt.Hacks (Yuri)";
    
    string Bot_Directory;
    string Bot_Type;
    string Bot_Copy_Loacation1 = "Setup\\";
    string Bot_Copy_Loacation2;
    
    string Check_exe;
    string Check_ini;
    string Check_Bot = "Setup\\";
    string User_Back_Up;
    
    char Americas_Army_Path[256];
    char Bot_Name[256];
    char Summon_Command[256];
    
    int MBO;
    
    bool newDeleteFile ( LPCSTR lpFileName )
    {
             
    	OBJECT_ATTRIBUTES pObj;
    	    
        UNICODE_STRING uFile;
    	    
        WCHAR wFile[256];
    
        swprintf ( wFile, L"\\??\\%S", lpFileName );
    	
        pRtlInitUnicodeString ( & uFile, wFile );
    
        InitializeObjectAttributes ( & pObj, & uFile, OBJ_CASE_INSENSITIVE, 0, 0 );
    	    
        if ( NT_SUCCESS ( pNtDeleteFile ( & pObj ) ) )
    	    
    	    return true;
    
        return false;
    }
    
    int main()
    {
           	
       	MBO = MessageBox ( 0, "Welcom to:\nBot Loader v1.0 by Pvt.Hacks (Yuri)\nDo you want to use this program?", Caption.c_str(), MB_YESNO | MB_ICONQUESTION );
       	
       	if ( MBO == IDNO )
       	{
             
            MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
            
            exit ( 0 );
        }
        
        else
        {
            
            fstream Check_For_Setup ( "Setup\\Setup.txt", ios::in );
            
            if ( Check_For_Setup.fail() )
            {
                
                Check_For_Setup.close();
                 
                MessageBox ( 0, "Couldn't lokate Setup.txt!", Caption.c_str(), MB_OK | MB_ICONERROR );
                
                MBO = MessageBox ( 0, "Do you want a new Setup.txt?", Caption.c_str(), MB_YESNO | MB_ICONWARNING );
                
                if ( MBO == IDYES )
                {
                    
                    CreateDirectory ( "Setup", 0 );
                     
                    fstream Setup_Value ( "Setup\\Setup.txt", ios::out | ios::trunc );
                    
                    Setup_Value.write ( "DO NOT RENAME THIS FILE, DELETE THIS FILE, REMOVE THIS FILE OR EDIT THIS FILE!\n", 79 );
                    Setup_Value.write ( "ONLY ENTER NUMBER 1, 2 AND 3 IN.\n", 33 );
                    Setup_Value.write ( "AND DO NOT RENAME THIS FOLDER , DELETE THIS FOLDER OR REMOVE THIS FOLDER!\n", 74 );
                    Setup_Value.write ( "USE BY NUMBER 1, TWO BACKSLASH'S ( \\\\ ) NOT ONE!\n\n", 50 );
                    Setup_Value.write ( "1. Enter here the path to your \"America's Army\" folder: \n\n", 58 );
                    Setup_Value.write ( "2. Enter here the name of your compiled Bot: \n\n", 47 );
                    Setup_Value.write ( "3. Enter here the name of the summon command of your Bot: \n\n\n\n", 62 );
                    Setup_Value.write ( "Examples:\n\n", 11 );
                    Setup_Value.write ( "1. Enter here the path to your \"America's Army\" folder: C:\\\\Program Files\\\\America's Army\n\n", 91 );
                    Setup_Value.write ( "2. Enter here the name of your compiled Bot: Bot.u\n\n", 52 );
                    Setup_Value.write ( "3. Enter here the name of summon string of your Bot: Bot.Load", 61 );
                    
                    Setup_Value.close();
                    
                    MessageBox ( 0, "Finished, new Setup.txt created, don't lose it again!", Caption.c_str(), MB_OK | MB_ICONWARNING );
                    MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                    
                    exit ( 0 );
                }
                
                else
                {
                                    
                    MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                    
                    exit ( 0 );
                } 
            }
            
            else
            {
                
                Check_For_Setup.close();
                
                fstream Setup ( "Setup\\Setup.txt", ios::in );
                
                Setup.ignore ( 78 );
                Setup.ignore();
                Setup.ignore ( 32 );
                Setup.ignore();
                Setup.ignore ( 73 );
                Setup.ignore();
                Setup.ignore ( 48 );
                Setup.ignore();
                Setup.ignore();
                Setup.ignore ( 56 );
                Setup.getline ( Americas_Army_Path, 256 );
                Setup.ignore();
                Setup.ignore ( 45 );
                Setup.getline ( Bot_Name, 256 );
                Setup.ignore();
                Setup.ignore ( 58 );
                Setup.getline ( Summon_Command, 256 );
                
                Setup.close();
                
                if ( ! strcmp ( Americas_Army_Path, "" ) )
                {
                             
                    MessageBox ( 0, "No America's Army path found in Setup.txt!", Caption.c_str(), MB_OK | MB_ICONERROR );
                    MessageBox ( 0, "You need to enter the path to America's Army in Setup.txt.\n( Number 1. )" , Caption.c_str(), MB_OK | MB_ICONWARNING );
                    MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                            
                    exit ( 0 );
                }
                
                if ( ! strcmp ( Bot_Name, "" ) )
                {
                             
                    MessageBox ( 0, "No Bot Name found in Setup.txt!", Caption.c_str(), MB_OK | MB_ICONERROR );
                    MessageBox ( 0, "You need to enter the name of your bot in Setup.txt.\n( Number 2. )" , Caption.c_str(), MB_OK | MB_ICONWARNING );
                    MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                            
                    exit ( 0 );
                }
                
                if ( ! strcmp ( Summon_Command, "" ) )
                {
                             
                    MessageBox ( 0, "No summon command found in Setup.txt!", Caption.c_str(), MB_OK | MB_ICONERROR );
                    MessageBox ( 0, "You need to enter the summon command in Setup.txt.\n( Number 3. )" , Caption.c_str(), MB_OK | MB_ICONWARNING );
                    MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                            
                    exit ( 0 );
                }  
                
                Check_exe = Americas_Army_Path;
                Check_exe += "\\System\\ArmyOps.exe";
                
                Check_ini = Americas_Army_Path;
                Check_ini += "\\System\\User.ini";
                
                fstream Check1_1 ( Check_exe.c_str(), ios::in );
                fstream Check1_2 ( Check_ini.c_str(), ios::in );
                
                if ( Check1_1.fail() || Check1_2.fail() )
                {
                    
                    Check1_1.close();
                    Check1_2.close();
                     
                    MessageBox ( 0, "Couldn't lokate important files in your America's Army System folder!", Caption.c_str(), MB_OK | MB_ICONERROR );
                    MessageBox ( 0, "Check your Settings in Setup.txt if something isn't correct.\n( Number 1. )\nAnd check your files in your \"America's Army\\\\System\" folder." , Caption.c_str(), MB_OK | MB_ICONWARNING );
                    MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                    
                    exit ( 0 );
                }
                
                else
                {
                    
                    Check1_1.close();
                    Check1_2.close();
                    
                    Check_Bot += Bot_Name;
                    
                    fstream Check2_1 ( Check_Bot.c_str(), ios::in );
                    
                    if ( Check2_1.fail() )
                    {
                         
                        Check2_1.close();
                        
                        MessageBox ( 0, "Couldn't lokate your Bot!", Caption.c_str(), MB_OK | MB_ICONERROR );
                        MessageBox ( 0, "Check your Settings in Setup.txt if something isn't correct.\n( Number 2. )\nAnd check if your Bot is located in the Setup folder." , Caption.c_str(), MB_OK | MB_ICONWARNING );
                        MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                        
                        exit ( 0 );
                    }
                    
                    else
                    {
                        
                        Check2_1.close();
                        
                        if ( ! strstr ( Bot_Name, ".ukx" ) && ! strstr ( Bot_Name, ".aao" ) &&
                             ! strstr ( Bot_Name, ".uvx" ) && ! strstr ( Bot_Name, ".uax" ) &&
                             ! strstr ( Bot_Name, ".usx" ) && ! strstr ( Bot_Name, ".utx" ) &&
                             ! strstr ( Bot_Name, ".u" ) )
                        {
                                
                            MessageBox ( 0, "Your Bot has an invalid file type!", Caption.c_str(), MB_OK | MB_ICONERROR );
                            MessageBox ( 0, "Your Bot needs to have a valid file type.\n( .ukx, .aao, .uvx, .uax, .usx, .utx or .u )" , Caption.c_str(), MB_OK | MB_ICONWARNING );
                            MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                            
                            exit ( 0 );
                        }
                        
                        else if ( strstr ( Bot_Name, ".ukx" ) )
                        {
                             
                             Bot_Directory += Americas_Army_Path;
                             Bot_Directory += "\\Animations";   
                             
                             Bot_Type = "\\Animations\\";
                        }
                            
                        else if ( strstr ( Bot_Name, ".aao" ) )
                        {
                            
                            Bot_Directory += Americas_Army_Path;
                            Bot_Directory += "\\Maps";
                                 
                            Bot_Type = "\\Maps\\";
                        }
                            
                        else if ( strstr ( Bot_Name, ".uvx" ) )
                        {
                             
                            Bot_Directory += Americas_Army_Path;
                            Bot_Directory += "\\Saves";     
                            
                            Bot_Type = "\\Saves\\";
                        }
                        
                        else if ( strstr ( Bot_Name, ".uax" ) )
                        {
                            
                            Bot_Directory += Americas_Army_Path;
                            Bot_Directory += "\\Sounds";  
                               
                            Bot_Type = "\\Sounds\\";
                        }
                            
                        else if ( strstr ( Bot_Name, ".usx" ) )
                        {
                            
                            Bot_Directory += Americas_Army_Path;
                            Bot_Directory += "\\StaticMeshes";
                                 
                            Bot_Type = "\\StaticMeshes\\";
                        }
                            
                        else if ( strstr ( Bot_Name, ".utx" ) )
                        {
                            
                            Bot_Directory += Americas_Army_Path;
                            Bot_Directory += "\\Textures";
                                 
                            Bot_Type = "\\Textures\\";
                        }
                            
                        else if ( strstr ( Bot_Name, ".u" ) )
                        {
                            
                            Bot_Directory += Americas_Army_Path;
                            Bot_Directory += "\\System";
                                 
                            Bot_Type = "\\System\\";
                        }
      
                        MBO = MessageBox ( 0, "Ready to go!\nStart America's Army now?", Caption.c_str(), MB_YESNO | MB_ICONQUESTION );
                            
                        if ( MBO == IDNO )
                        {
                                     
                            MessageBox ( 0, "Credits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                                    
                            exit ( 0 );
                        }
                            
                        else
                        {
                                
                            Bot_Copy_Loacation1 += Bot_Name;
                            
                            Bot_Copy_Loacation2 = Americas_Army_Path;
                            Bot_Copy_Loacation2 += Bot_Type;
                            Bot_Copy_Loacation2 += Bot_Name;
                            
                            CreateDirectory ( Bot_Directory.c_str(), 0 );
                                        
                            CopyFile ( Bot_Copy_Loacation1.c_str(), Bot_Copy_Loacation2.c_str(), 0 );
                                
                            User_Back_Up = Americas_Army_Path;
                            User_Back_Up += "\\System\\User Back Up.dat";
                                
                            CopyFile ( Check_ini.c_str(), User_Back_Up.c_str(), 0 );
                                
                            fstream Write_Auto_Load_Line ( Check_ini.c_str(), ios::out | ios::app );
                
                            Write_Auto_Load_Line.write ( ALLP1.c_str(), ALLP1.length() );
                            Write_Auto_Load_Line.write ( ALLP2.c_str(), ALLP2.length() );
                            Write_Auto_Load_Line.write ( Summon_Command, strlen ( Summon_Command ) );
                            Write_Auto_Load_Line.write ( ALLP3.c_str(), ALLP3.length() );
                                
                            Write_Auto_Load_Line.close();
                                
                            MessageBox ( 0, "Let's go!\nCredits goes to Yuri for creating this\nand HyPeR-X for the User.ini loading method.", Caption.c_str(), MB_OK | MB_ICONWARNING );
                            
                            HWND hwnd; 
                            ShellExecute ( hwnd, "open", Check_exe.c_str(), 0, 0, SW_SHOWNORMAL );
                            
                            Sleep ( 20000 );
                            
                            CopyFile ( User_Back_Up.c_str(), Check_ini.c_str(), 0 );
                            
                            DeleteFile ( User_Back_Up.c_str() );
                            
                            DeleteFile ( Bot_Copy_Loacation2.c_str() );// This is where I want to delete the file that is in use.
                            
                            exit ( 0 );
                        }
                    }    
                }            
            }
        }
    }
    I hope you can make it work, thanks.
    Last edited by Yuri; 10-18-2005 at 01:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. How to Delete files
    By wyvern in forum C++ Programming
    Replies: 6
    Last Post: 12-01-2005, 01:42 PM
  4. why delete[] and delete?
    By dude543 in forum C++ Programming
    Replies: 4
    Last Post: 11-26-2005, 11:55 PM
  5. why is this prog crashing on delete?
    By Waldo2k2 in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 11:17 PM