Quote Originally Posted by Alimonster
You can read a running exe by using one of the mode flags in TFileStream.Create, I believe - open in "fmOpenRead or fmShareDenyWrite" [or maybe "fmOpenRead or fmShareDenyNone"]. A quick test suggests that they work fine reading from a running exe file.

Can't answer your second question, though I'll give you some speculation. Are you trying to include a checksum onto an exe to check whether it's been altered? If so, write your standard "CheckCRC32" function inside of your main code (or other suitable checksum function). Compile your project into an exe file.

Use an external utility w/ the same function (just copy and paste it into another project) to generate a fixed-size checksum based on the compiled exe. Append this checksum value to the end of the exe. When running the exe, you would read all the exe data up to the start of the checksum. You'd do the calculation and compare to the externally generated checksum.

Bear in mind that this will be very fiddly - you'll have to manually generate a new checksum each you recompile, which will be a royal pain in the ass. Also, you have to remember that the checksum value shouldn't be read in with the rest of the exe when calculating at run-time - it wasn't involved in the first place!
Your reply is as genius as always Thanks, just what I was looking for! I had previously thought about hard coding a dummy checkum 'inside' the exe (eg. $FFFFFFFF) then calculate the actual checksum of the exe without the 2 words where the checksum is stored, then manually edit that location in the exe to include the actual checksum. It's a bit easier adding it to the end of the exe.