如何向从网络下载的exe传递参数?

发布于 2024-10-07 16:06:35 字数 117 浏览 1 评论 0原文

我有 .Net 桌面应用程序,用户可以从我的网站下载。我想根据每个用户自定义这个应用程序。 有没有办法在下载之前修改exe,只需更改一些适合用户下载的字符串? 或者可以通过 URL 将命令行参数传递给此 exe 吗?

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 command line parameters to this exe via URL ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如果没结果 2024-10-14 16:06:36

如果应用程序是 ClickOnce 部署的,则传递 URL 参数是 ClickOnce 选项对话框中的一个选项。不过,我还没有使用过这个功能。

编辑
您可能需要根据实际运行应用程序的用户更改配置中的某些用户设置。您还可以通过在初始初始化后添加适当的 SettingsNeedUpdate 设置(在初始初始化后设置为 true)来确保每个用户仅执行一次此操作。

示例:
添加新设置“Option1”、“Option2”和“SettingsNeedUpdate”,它们是用户设置。在 Main 中,您可以添加如下内容:

...
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)
{
    ...
}

...

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)
{
    ...
}

...
骑趴 2024-10-14 16:06:36

您可以编写一个可以修改程序集资源(此处为字符串表)的库。
该库可以从反思中受益。

当用户请求您的文件时,asp.net 页面可以自定义 exe(使用您的库)并将其发送到客户端。

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.

疯狂的代价 2024-10-14 16:06:36

不是那样的,不。

但是,您可以使用每个用户的自定义 app.config 文件自动压缩(在您的服务器上)您的 exe。

更新

将您的下载位置指向将您的 exe 压缩在一起的自定义 HttpHandler(使用 http ://www.sharpdevelop.net/OpenSource/SharpZipLib/),并生成(针对当前用户)应用程序配置文件( http://generally.wordpress.com/2007/09/27/using-appconfig-for-user-defined-runtime -参数/)。

然后,用户将两个文件(MyApp.exe 和 MyApp.exe.config)解压缩到任意位置并运行 MyApp.exe。

如果您有安装程序,则此方法不起作用。

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.

离旧人 2024-10-14 16:06:35

.exe 文件 需要对其进行自定义,以使其对某些下载有不同的行为。

跳过下面找到我认为可以忍受的解决方案。

将部分添加到 .EXE 文件 - 不理想。

.exe 文件具有一个接一个的部分。您可以添加一个包含数据的部分,然后可执行文件将读取该部分。这要求您修改(有权访问)可执行文件的源代码,以便它对数据执行任何有意义的操作。另外,熟悉 .exe 文件格式并在 Web 服务器端修改它以及在程序源代码中使用它有点乏味。

更改 .EXE 文件的资源部分 - 不理想。

可执行文件中存在专用的“资源”部分。您可以向其中添加自定义字符串或数据块。与第一个相同的缺点。

在 .EXE 中的固定位置覆盖数据 - 可以通过。

让可执行文件从文件中的固定位置读取自身数据,在提供 .exe 文件时,该数据将被自定义数据覆盖。需要修改可执行文件的源代码。

将数据附加到 .EXE – 可以通过。

将数据附加到可执行文件。同样,读取它并用它做任何特殊的事情都需要可执行文件本身这样做。


☑ 将 .EXE 包装在另一个 .EXE 中并将数据附加到其中 - 可以容忍。

创建一个程序,将原始可执行文件和自定义数据附加到其中。当执行此自定义程序时,它将提取嵌入的可执行文件并使用自定义数据作为参数启动它。

这种捆绑可执行文件也很容易在大多数服务器端(脚本)语言上生成。当请求下载时,服务器会发送包装器 exe、原始 exe、自定义数据,当然还有一些静态大小的数据字段,表示这两个数据块的大小,以便服务器可以提取它们。

缺点:需要创建这样的包装程序,除非有人已经创建了。

相关链接:
1. 让我的网络用户使用 PHP 从我的网站下载自定义 .exe 的最佳实践
2. 在下载时修改可执行文件(如 Ninite)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文