Thread: Delte file

  1. #1
    Registered User Bitojis's Avatar
    Join Date
    Jun 2005
    Posts
    20

    Delte file

    Hello, I have a little problem. I create a file, wich contains text. Here is the code
    Code:
    //---------------------------------------------------------------------------
    
    #pragma hdrstop
    #include <stdio.h>
    #pragma argsused
    
    
    void main(int argc, char* argv[])
    {
    char texto[255];
    FILE *fichero;
    
    printf("Introduzca un texto que no exceda los 255 caracteres, para acabar presione enter: ");
    
    gets(texto);
    fichero=fopen("c:\\exploit.exe", "w+");
    fprintf(fichero,texto);
    fclose(fichero);
    
    }

    The problem is that when I go to C:\exploit.exe and I try to delete the file, the computer says me that the file is in use. I close the compiler, but, again, I canīt delete it. Can anyone help me?

    Thanks,

  2. #2
    FOX
    Join Date
    May 2005
    Posts
    188
    Lets see...

    1) void main
    2) gets()
    3) exploit.exe

  3. #3
    Registered User Bitojis's Avatar
    Join Date
    Jun 2005
    Posts
    20
    Can you specify it to me, please?

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    It's simple. Some other process is acessing the file, so you can't delete it. Since it's a exe, I believe it's that program itself that is running. You first have to kill the app, then delete it.
    Plus, to delete a file use function remove(const char* filename); from stdlib.h

  5. #5
    Registered User Bitojis's Avatar
    Join Date
    Jun 2005
    Posts
    20
    I also think that the program is runnig by itself, but when I look in windows process, I donīt find it, so I canīt stop it.

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    so there's another process acessing it. Could be(almost for sure) explorer.exe or if you're unlucky some virus that opened the file for infection :P
    You can download a free trial of tune up utilities which has a task manager, that shows all open files on the host machine. That way you can see which process is locking the exe.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The easiest way to get rid of this problem for good is to stop using Windows.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    I typecast anyway.
    Join Date
    Jun 2005
    Posts
    25
    Sometimes the easiest way to loosen something's grip on a file is to just reboot the machine. If that fails, you could try a virus scan. I use http://housecall.trendmicro.com because it's free and it catches a pretty good percentage of the viruses out there (even some spyware, now). It's ActiveX so you'll probably have to run it in Internet Explorer.

  9. #9
    I typecast anyway.
    Join Date
    Jun 2005
    Posts
    25
    By the way... why are you writing plain text to a .exe file?

  10. #10
    Registered User Bitojis's Avatar
    Join Date
    Jun 2005
    Posts
    20
    I am doing a C exercise that says me to do that. This is the first part of the exercise, then I have to use this .exe file to do other things (I donīt know yet whatīll be the use of that .exe).

    Iīve checked for virus with my Norton, and it havenīt found anything. Also, I rebooted my computer. It worked untill I run the program, then, another time the same thing, I canīt delete it. Any idea?

    Thanks,

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Does this work?
    Code:
    #include <stdio.h>
    int main( void )
    {
        FILE *fp;
    
        fp = fopen( "foo.bar", "w" );
        if( fp )
        {
            fputs( "baz", fp );
            fclose( fp );
        }
    
        fp = fopen( "foo.bar", "r" );
        if( fp )
        {
            printf( "Well, it works.\n" );
            fclose( fp );
        }
    
        return 0;
    }
    If it does, your file either doesn't exist, or is being grabbed by some other program.


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User Bitojis's Avatar
    Join Date
    Jun 2005
    Posts
    20
    The file that is using it is explorer.exe, so it is the windows explorer. But I donīt know why is using it. Any idea?

    Thanks,

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Give it up, it's a lost cause. Just rename it to something else and carry on with your "lesson".


    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    explorer open that file an tries to reach its headers to find out for which OS it is targeted, and also tries to read icons for display in the explorer shell. Since that executable isn't valid (I think) it gets stuck. This and dealing with corrupt media files are explorer worst issues.

  15. #15
    Registered User Bitojis's Avatar
    Join Date
    Jun 2005
    Posts
    20
    Is there any solution?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM