开发者

How to pass parameter to exe downloaded from web?

开发者 https://www.devze.com 2023-01-30 21:14 出处:网络
I have .Net desktop app which users can download from my website. I want to customize this app to per user basis.

I have .Net desktop app which users can download from my website. I want to customize this app to per user basis. Is there way to modify exe before downloading, just to change few strings with appropriate for the users downloading ? Or it is possible to pass co开发者_运维技巧mmand line parameters to this exe via URL ?


The .exe file needs to be customized for it to behave differently for certain downloads.

Skip below to find the solution I found tolerable.

Add section to the .EXE file – Not ideal.

The .exe file has sections one after the other. You could add a section with your data in it, which the executable would then read. This requires you to modify (have access to) the source code of the executable for it to do anything meaningful with the data. Also getting familiar with the .exe file format and modifying it on the web server side as well al playing with it in the program's source code is somewhat tedious.

Change resources section of the .EXE file – Not ideal.

A dedicated "resources" section exists in the executable. You could add custom strings or blob of data to it. Same cons as the first one.

Overwrite data in the .EXE at a fixed position – Passable.

Have the executable read data from itself from a fixed position in the file, which is overwritten with the customization data when serving the .exe file. Requires modifying the executable's source code.

Append data to the .EXE – Passable.

Append data to the executable. Again, reading it and doing anything special with it requires the executable itself doing so.


☑ Wrap the .EXE in another .EXE and append your data to it – Tolerable.

Create a program to which the original executable and the custom data will be appended to. When this custom program is then executed, it will extract the embedded executable and launch it with the custom data as it arguments.

This kind of a bundle-executable is also easy to produce on most server-side (scripting) languages. When the download is requested, the server sends the wrapper-exe, the original exe, the customized data and of course some statically-sized data fields denoting the sizes of both of those data blocks so it can extract them.

Cons: Requires such a wrapper program to be created, unless someone already has.

Related links:
1. Best practices to let my web users download custom .exe from my site using PHP
2. Modifying executable upon download (Like Ninite)


If the application is ClickOnce deployed, passing URL parameters is an option in the ClickOnce options dialog. However, I have not yet used this feature.

EDIT
You might want to change some user settings in your configuration depending on the user that actually runs the application. You could also make sure this is done only once per user by adding an appropriate SettingsNeedUpdate setting you set to true after the initial initialization.

Example:
Add new setting "Option1", "Option2" and "SettingsNeedUpdate" which are user settings. In Main you could add something like:

...
try
{
    if (Properties.Settings.Default.SettingsNeedUpdate)
    {
        Properties.Settings.Default.Option1 = ...;
        Properties.Settings.Default.Option2 = ...;
        Properties.Settings.Default.SettingsNeedUpdate = false;
        Properties.Settings.Default.Save();
    }
}
catch (Exception exp)
{
    ...
}

...


You could write a library which can modify an assembly resources (here string table). This library could benefit from reflection.

When a user asks for your file, asp.net page could customize the exe (using your library) and send it to client.


Not like that, No.

You could however automatically zip (on your server) your exe with a custom app.config file for each user.

Update

Point your download location to a custom HttpHandler that zips together your exe (using http://www.sharpdevelop.net/OpenSource/SharpZipLib/) with a generated (for the current user) application configuration file ( http://generally.wordpress.com/2007/09/27/using-appconfig-for-user-defined-runtime-parameters/).

The user then unzips the two files (MyApp.exe & MyApp.exe.config) to any location and run MyApp.exe.

This method does not work if you have an installer.

0

精彩评论

暂无评论...
验证码 换一张
取 消