Hi, I am writing a program to store basic information such as name and address but i want to be able to store this information as a separate file.
So for example i could fill out the Name as 'Mary' and then save this as an executable file which I could open and i would repeat the information i entered into it namely "Mary".
I am still fairly inexperienced in C# so code would be useful.
Sorry if I wasn't clear.
I want to be able to fill in text boxes containing Name, Country, Gender etc and then have an option to save the file as an .exe so that i can just open up that specific save and see just the info that I saved.
Save your info as a text file with extension .txt
If you doubleclick it in Explorer, the executable NotePad will open and you can read the contents of your textfile. To make an executable file from your info would be a little difficult I guess. You would have to write a compiler for that.
Would you have any idea on how to do that, I would prefer to not use notepad.
What are you really trying to do here? This project doesn't make much sense. You could override the default program associated with ".txt" and open it in any editor you like. If you change the default extension handler on someone elses machine it will probably irritate them so I would not recommend this for a production application.
Ok I'll try and explain exactly what i'm trying to do.
These are the labels i have with textboxes next to them, there is a file bar at the top with a 'save' option.
If i fill out the form name 'mary' the Gender 'female' and the country 'New Zealand' then go to the menustrip and select save, it will save this to the folder the application in already. I want the file i just saved to be an exe file so when i open it it will have simply.
Country: New Zealand
Or the info i entered in the application.
So i want to be able to save a seperate exe file containing information saved.
Why do you want it to be an .exe file? You could make your own file extension and register a console program to open that file. So when you double click on the file it opens with your program. You could name your extension
.wingers and create a little "View" program. Imagine if every Microsoft Office Word Document was its own executable with the document information inside of it. Do you see how that is a bad idea?
You also haven't said how you want the information to be displayed on the screen. You could have a read-only form display the file, you could pop it open in a .NET report, you could write it as output in a command window... the possibilities are endless.
Thanks for the input.
The main reasons I wanted it to be a exe is so it does not require another program to open.
But i see your point and would ask how this is best done, code examples would help, thanks.
Unfortunately I don't have any code examples for this task. What you're after is "registering file extensions".
What you originally asked is possible but it is a lot of work. There are two ways I know of going about -- and neither work in .NET as far as I know, but i'm sure you could find a way.
First with C (and I don't know C, only the concept so bear with me) you can declare a struct in the C binary of a static length and prefix the struct with a signature. Then you would locate your struct in the executable by the signature and you could write N bytes in to the executable. This would allow you to write any data required directly in to the executable file. Now I have seen this done on Linux but not on Windows but it would work on windows. With Linux once you have the program running in memory you can delete the executable. So you could launch the program then rewrite the executable that launched the current process. With windows you will get a "File in use" error -- so you would need two copies of the program. Execute the original then create a copy of the launching executable with the modified internal data and save it as a copy -- which is what you asked.
Somehow the above mentioned way can get around the checksum on C binaries. I don't know if you have to go about excluding this region of writeable data from the checksum calculator or if the checksum simple ignores structs. You would need to look that up.
The other way I know of is using UPX to attach files in an .EXE. I use this for Delphi but for different reasons. You can use UPX to pack an executable file and basically it behaves like an executable zip file but the user doesn't know there are files embedded. UPX has a loader to launch your program then your program needs to be aware it is UPX packed and figure out how to get the information out.
I UPX pack my Delphi applications so I can include the linker generated .map files (basically it is the same as the .pdb files in .NET) so when my application crashes (yes it does happen sometimes :() I bring up a neat little crash screen to submit bug reports. The application accesses the UPX packed MAP file at crash time so it can generate a very detailed debug report with the line numbers. You can see this in .NET too -- if your application crashes and has the .pdb file in the same directory you get line numbers in the call stack. If no .PDB is present then you only get a call stack with method names but no line numbers.
There is also a negative performance impact for writing executables like this. You have a PREFETCH in Windows which has a copy of each unique executable you run: C:\WINDOWS\Prefetch. When you use UPX it launches the stub program loader which unpacks your executable file in to memory and launches the executable from memory. This means if your application is running on a terminal server then multiple users can't share the same application from windows' prefetch because they're sharing the stub-loader, meaning you will use more memory per each unique instance of the application running on the same machine.
Also with your case each application would have different data embedded internally so the checksum for each binary would be different.
Now .. all of that being said ... you really don't want to use the executable approach. Take a stab at registering file extensions ;)
I have an Epson receipt printer (Model number: TM-T88V), but I cannot use it. I do not have a POS (point of sale) software that will let me do what ...
I have a datatable in Winforms.
I am currently trying to find the max and min values for each of the columns for each row. My table layout is like ...
This code generates an ascii maze of up to size 30x30. If you try to generate a larger maze then you will likely run out of stack space. There is ...