Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving to .exe

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
SE
Greetings all...

I was just wondering if the possibility for a program to write to itself, or will the read-only rights prevent it! (that is application.exe wants to write to itself while running)...

I recall that I once saw a post(long ago) about implementing a default file into the exe which you could extract.. but I couldn't find it again!! (any clue about this too?).. cause it was beacuse of this "memory" I ask.

it is something like that I want to do, implement an .txt. but instead of reading from it, I want to save!?(if you can understand :))


thanks in advance for any ideas...
/801119 My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
you could turn off the read-only rights, but why in the world would you want to write to your executable? Do you mean something like add code to the application and recompile it?

In a perfect world... maybe.

Chances are, there's ways to do what you want without having to write to the exe. What exactly would you want to write?


And about the .txt, I'm not exactly sure what you mean. Do you want to write to a .txt file and read from it in code?

Cyprus
[noevil]
 
Cyprus,

I'm sorry for the somewhat fuzzy explaination. I'll brief you on the "project" my brother asked me to start on.

He asked me to write a program that works like post-it notes. A small window that can either float on the desktop, or be hidden in the tray!
In this program, when something is written(or changed), and upon closing, the program saves that information to its own executable file (.exe)

I asked him why he didn't like the idea of having .txt files, and he said: "it makes it easier to move it all, and had I wanted several copies I would have to put them in differnet directories"... he also said that it would be to much alike all other windows progams! (whatever he ment by that)...


And to answer your question, No, I don not want to recompile the progam, I simply want to add a block into it, similar to something like this

[block][executable code]

or the other way around. and I also want to be able to overwrite this 'block' without interfearing with the remaining 'executable code', and all done without having to recompile it! (but I have my doubts about whether or not this is doable)

thanks, hope it made a little more sense this time!! :)
and if it's impossible(for me, or at all) to do this, then he'll have to cope with .txt files! My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
He'll probably have to cope with .txt files. You can't write to the executable while it's running, but you might be able to do a roundabout method of what you want.
try this:

-Run the executable
-when you want something to change, copy the exe to another location, (say temp\\backup.txt)
-write to that executable
-run it
-shut down the original

-have a function inside of the executable to check it's curent location (maybe ExtractFilePath(myapp.exe))
if it finds out it's in the temp file, have it
*first check to see if the original exe is running. Save yourself an error
*delete the original exe
*copy itself back to the original spot
*run the copy and shutdown

-now the copy of the copy is "the original" have it do the same method to delete the first copy

Alright, I know that was pittifully confusing, sorry.


You might be able to append data to the end of the exe. The problem is that when you run it, the assembler could try to read your blocks and you'd be in some trouble.

If your just doing this for your brother, I suggest you not even try. Going about what you want to do is just not worth it. You'd be much better off using .ini's, or the registry.


see:
thread207-243525 Cyprus
[noevil]
 
Why not simply write keys to the registry or an ini file? Or are you wanting this program to be entirely self-contained, thereby when/if moved, it still contains the notes for the "Post-its"?
 
Cyprus,

after some evaluation I've come to the same conclusion that it isn't a good idea to do it this way! (least not the way I've figured out.. no need to explain and make you all feel dizzy :)), anyhow, that thread gave me an idea on how to pack files into the .exe (through an external link that led to me a source-code)however, it doesn't say it's possible to write while running. So your suggestion, to launch a copy of the program and do it that way

But I feel I don't have enought experience to start goofying around with that! :)

And KyferEz, indeed that is exactly what I am trying to accomplish. Do you know a way to do this?!
My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
If you want to transfer the data to different computers, then you do not want to use registry. It cannot transfer. If you save the ini along with your program, not in the default folder (windows) then you can transfer that.

see: faq101-72

search in help for registry, ini should be somewhere like see also. either that or search for IniFile. Cyprus
[noevil]
 
The ini/registry, yes.
To write your notes into the program, no.

If you think about it, it doesn't seem possible. All this code is compiled into hex, and when written, the functions refer to memory locations. Writing to the file would change the size of the file and locations in memory, and destroy things.

I reccommend an ini file, which you could also use to save preferences, and it could be copied with the programs directory and be used on any machine.
 
I have done something like this once. I was trying to do a date stamp for a shareware program (only runs 30 days) that would follow the executable (DOS days).

I created an array of characters that was hardcoded into the code of the program itself:

char storspace[] = "[START OF DATA]...[END OF DATA]"

I then searched the exe for "[START OF DATA]" and "[END OF DATA]" and knew that everything inbetween those two points was data that was not being used by the application and was set aside for data storage.

You would have to set aside a HUGE array and the minute it was filled, the person is out of luck. Basically, they would have used up all of the pages [memory] in the book [exe].
 
Now, i have only done this in C++ running DOS but i made a program killing itself after a trial period by writing an "return to sender" code into the executable file.

It was not locked when running so appending the .exe file should pose no problem, at least under DOS, with Win i do not know.
 
That's similar to what I was doing. I didn't know you could append to an executable without harming it. If you can do that... Interesting...

(Oh no. Now I'm going to break something.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top