Writing in files that are in use?

This is a discussion on Writing in files that are in use? within the C++ Programming forums, part of the General Programming Boards category; Hi. Is there a way to write in a file that is in use ( on this way: ios::out | ...

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

    Writing in files that are in use?

    Hi.
    Is there a way to write in a file that is in use ( on this way: ios::out | ios::binary | ios::trunc )?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    yes, unless the other program opened it in exclusive mode or "deny write" mode.

  3. #3
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Is there an (easy) way to find that out and how can I change it on a way that it isn't on "deny write" mode?
    Thanks Yuri.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Yuri
    Is there an (easy) way to find that out
    try to open the file.

    Quote Originally Posted by Yuri
    and how can I change it on a way that it isn't on "deny write" mode?.
    You can't. The other program opened it like that for good reason -- it woesn't want anyone pulling the rug from under it. The other program may be in the process of writing to the file, so if you were to write to the same file you would really fu**k it up! The file would be nearly useless for anyone.

  5. #5
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Ok, the file is only in use for reading by another process, I foung something on MSDN, it's called Unlockfile
    http://msdn.microsoft.com/library/de...unlockfile.asp could that help me with unlocking the file and make it writeable because I don't really understand it on MSDN.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    As Ancient dragon said, you don't want to write to a locked file because it may be in use by another programme. It makes sense to me.

  7. #7
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    No it doesn't to me because I know the situation, I'll explain: The file I hook up in the process can after being loaded into the process deleted (I mean with deleted: it wont effect the process to crash) even when it's in use (what it always is) by that process after being loaded then you can delete (I mean with deleted: it wont effect the process to crash) the file with "ForceDel.exe" and the file is gone and then you can put the file that it replaces back, everyhting is then fine, the reason why the Process still use the file is because it is a protection against cheaters, the reason that I need to rewrite the file after being loaded in the process is because the file needs to be the same as the file it replaces, if the file isn't the same as the file it replaces then it will get a md5 mismatch and I get caught. That is why I want to 'Unlock' the file to make it writeable and to bypass the md5 tool.

  8. #8
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Quote Originally Posted by bumfluff
    As Ancient dragon said, you don't want to write to a locked file because it may be in use by another programme. It makes sense to me.
    Kill the other programs handle on the file, then it's possible.

  9. #9
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Yeah, I was thinking about to kill the handle on that file but I can not kill the whole process because then the 'game' will stop running and that is not what I want... now I saw a program (procexp.exe) which is pretty usefull because if you select the 'game' then you will see (after a bit of scrolling) under "Type" that it is a File (we all knew that) and then the Path and FileName then I simple click with left mouse on that file which is running under the 'game' and press 'Close Handle' now everything is fine and I can rewrite or delete the file but the thing is:

    I want to do (almost) the exact same thing, to close the handle on that file, nothing more because else the 'game' will get closed too. But I want it in my program and not to Alt + Tab out and etc. I know TerminateProcess but what to do if only want to close a certain file of the process (the 'game')?? Thanks Yuri.

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  11. #11
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Thanks but I already know that site and got the source.. the thing that I don't understand it, example: if I would use a part of his source and I want that it only deletes a certain file.. where do I need to put the "path\\filename" string?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with writing to files
    By beanroaster in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2007, 12:21 AM
  2. Reading & Writing files (Error)
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2006, 11:55 AM
  3. Writing files to a CD
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 04-16-2003, 05:43 PM
  4. *.COM Files? Writing them?
    By johnc in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-11-2002, 02:52 AM
  5. Making files, opening them, and writing to them
    By Unregistered in forum Game Programming
    Replies: 6
    Last Post: 06-18-2002, 10:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21