tags:

views:

465

answers:

5

Under Windows is there a way to modify a file/executable opened by another process using c++?

A: 

Thanks but that was not quite what I meant. I was looking for a way to modify a file that another program has open or an executable that is running.

No, you can't do it.
Adam Rosenfield
Please amend your question - do not add an 'answer' to explain your question.
Jonathan Leffler
+7  A: 

Is there a way to modify an open executable in windows?

No.

Is there a way to modify an open file in windows using c++?

Yes. If it has been opened with the proper share permissions. See http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx FILE_SHARE_WRITE

SDX2000
+1  A: 

It may be possible but perhaps not easy to achieve. You need inject thread in destination process and know PE format for correctly edit opened file and modify it.
All information is on web.

Good Luck.

I find this freeware tool, it proposes to unlock files and folders.

lsalamon
A: 

The OS holds the executable file open for read-only sharing as long as it's running, so there's no way to modify it directly. You can, however, open it for reading (if you specify read-sharing in your CreateFile call), and make a modified copy of it, while it's running.

I don't know if that's what you had in mind, but if it's your own program you're doing this to, you can start the new copy and have it pick up where the previous one left off... not straightforward, but not all that difficult either.

Head Geek
A: 

Of source it's possible.

Just hook it