Question

I have a window application which performs some tasks, One of which is opening some files and we all know .net provides exe file for the application, which can be used as click to start. I am calling this application application1.

Now I want to generate one more window application(simple exe), let us call it application2, which will open a form with some options(say the names of the files to be opened by application1) and a generate button.

On clicking the generate button, it should generate the exe file for the application1 with the data passed from application2.

Please suggest how can I do it.

EDIT I need to generate exe which will be available on different systems which will perform some task on regular intervals. and the interval colud be different for different computers. so I am asked to generate which will accept the time interval and will generate the exe for that interval

Was it helpful?

Solution

I think what your looking for is for application1 to be able to receive command line arguments and application2 to allow you to pick files and run application1 and pass in those arguments.

I don't think its wish to be generating .exe's

OTHER TIPS

There are a number of ways to consider doing this:

  1. use a reg key with the name of the settings file to read in, and then store the settings you write from app2, for app1 in the file, so app 1 can run it

  2. you call app1 with a parameter with either the name of a file, or commandline parameters, and it updates its own applications settings file.

  3. put the settings in a database, so any copy of app1 anywhere can find it, assuming all users would be able to see the db server

  4. if app1 is always to be running while app2 is you could go with some interprocess communication but probably this is the more complex of the 4

Rather than recompiling an exe, it would make sense to have a config file that goes with.

Failing that, compiling .net is only that, you can have an exe that generates a .cs file (or updates one, and reruns the whole compile and outputs an exe.. take a google, on command line compilation) but I wouldnt be my choice.

Another way, although not that easy, would be to

  • write application 1 to try and read settings from class that does not exist, say SettingsOverride, by reflection; if not found, fall back to its own hard-coded settings
  • application 2 uses CodeDOM or similar to create a new assembly that provides a SettingsOverride class with the new saved settings
  • application 2 uses ILMerge to build the new .exe from application 1 and the settings assembly; the reflection code in application 1 should now pick up the new settings.

It's probably also possible to do this with embedded resources, though I'm not sure how. Finally you could put a string constant in your .exe, say 400 X characters, and then application 2 could scan the file to find that (as Unicode/UTF-16 text) and replace that with a string containing the new settings - but I'm not 100% if you then need to recompute a checksum or similar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top