将个性化代码嵌入 ClickOnce setup.exe 中?

发布于 2024-12-02 12:41:26 字数 453 浏览 1 评论 0原文

我知道可以通过 URL 将参数传递到在线启动的 ClickOnce 应用程序。但是,大多数用户下载 setup.exe 并从他们的计算机启动它。有什么方法可以在下载时重写 setup.exe,插入代码(假设用户的电子邮件地址),然后在了解代码的情况下启动应用程序?假设我们可以以某种方式重新签名 setup.exe,使其合法。

假设.NET 3.5。

更新 这里的目标是将电子邮件地址和/或引用信息传递给 setup.exe,这样即使用户从不同的计算机和不同的 IP 运行安装程序,我们也可以找出是谁执行的转介。

更新 2 假设是 .NET 3.5 SP1,有帮助吗?显然,现在可以在离线状态下将参数传递给 .application。是否可以将参数嵌入到 setup.exe 中,以便在 setup.exe 运行时调用 .application?ref=someone ?

I know that it is possible to pass in parameters via URL to ClickOnce apps launched online. However, most users downloads setup.exe and launch it from their machine. Is there any way that I can re-write setup.exe at download, insert a code (let's say the user's email address), and then have the app launch with knowledge of the code? Assume that we can somehow re-sign setup.exe so that it is legit.

Assume .NET 3.5.

Update The goal here is to pass on either email address and/or referrer information to setup.exe so that even when the user runs the installer from a different machine and a different ip we can figure out who did the referral.

Update 2 Assume .NET 3.5 SP1, does it help? Apparently one can now pass parameters to .application while offline. Is it possible to embed parameters into the setup.exe so that it calls .application?ref=someone right when setup.exe is run?

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

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

发布评论

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

评论(5

长亭外,古道边 2024-12-09 12:41:26

好吧,如果您的目标是将客户 ID(电子邮件、代码等)嵌入到 exe 中,我能想到的最简单的方法是使用 IPropertyStorageIPropertySetStorage 接口。如果您足够勇敢,您可以通过 p/invoke 直接调用 IPropertySetStorage 上的方法,或者您可以采用简单的方法并使用 Microsoft 准备好的 COM 包装器,该包装器称为 dsofile.dll

请注意,虽然 dsofile 适用于 Office 文档,但它确实适用于任何文件(包括 .exe 文件),您只是受困于预定义的属性名称。为什么不将您的客户 ID 放入 .Comments 属性之类的内容中。只需以这样的方式进行即可再次解析它。

这是一个示例:

var doc = new OleDocumentPropertiesClass();
doc.Open(pathToFile);
doc.SummaryProperties.Comments = "[email protected]";
doc.Save(); 

当然,您需要首先将其复制到临时位置,并且在用户下载它后的某个时间您会想要将其删除。

您可以将 dsofile.dll 与您的应用程序捆绑在一起,并将其注册为依赖项,并在安装程序中使用它来读取属性。或者,如果您可以在没有它的情况下 p/调用 IPropertyStorage,那么您将不会有依赖性。

另一件需要研究的事情是使用 Shell32.dll 读取的扩展文件属性。我只是无法找到一种干净的方法来轻松地编写它们。如果您采用此方法,请分享您如何将属性写入 .exe。

Well, if your goal is to embed a customer id (email, code, etc) into the exe, the easiest way I can think of is using the IPropertyStorage and IPropertySetStorage interfaces. If you are feeling brave, you could call methods directly on IPropertySetStorage via p/invoke, or you could go the easy route and use Microsoft's prepared COM wrapper, which is called dsofile.dll.

Note that while dsofile is intended for office documents, it does indeed work on any file - including .exe files - you are just stuck with the pre-defined property names. Why not throw your customer id into something like the .Comments property. Just do it in such a way that you can parse it out again.

Here's a sample:

var doc = new OleDocumentPropertiesClass();
doc.Open(pathToFile);
doc.SummaryProperties.Comments = "[email protected]";
doc.Save(); 

Of course, you need to first copy it to a temp location, and some time after the user downloads it you'll want to delete it.

You can bundle dsofile.dll with your application and register it as a dependancy and use it in your installer to read the property back out. Or if you can p/invoke the IPropertyStorage without it, then you won't have the dependancy.

The other thing to look into would be using the extended file properties that are read by the Shell32.dll. I just haven't been able to find a clean way to write them easily. If you go this route, please share how you wrote the properties to your .exe.

温柔嚣张 2024-12-09 12:41:26

看看 InPlaceHostingManager 类在这种情况下是否可以帮助您。它可能不会完全满足您的要求。但也许能帮上忙...

任何基于 .exe 文件的 ClickOnce 应用程序都可以静默运行
由自定义安装程序安装和更新。自定义安装程序可以
在安装过程中实现自定义用户体验,包括自定义
用于安全和维护操作的对话框。执行
安装操作,自定义安装程序使用
InPlaceHostingManager 类。

演练:为 ClickOnce 应用程序创建自定义安装程序

编辑

我不确定您是否可以完全按照问题中描述的方式实现您想要的目标。检查这些线程是否对您有帮助。

访问 ClickOnce 应用程序中的本地和远程数据

<一个href="https://stackoverflow.com/questions/2414823/how-to-include-custom-data-files-in-clickonce-deployment">如何在 ClickOnce 部署中包含自定义数据文件?

如何:检索联机中的查询字符串信息ClickOnce 应用程序

Have a look whether InPlaceHostingManager class can help you in this case. It won't probably do exactly what you have asked for. But may be able to help...

Any ClickOnce application based on an .exe file can be silently
installed and updated by a custom installer. A custom installer can
implement custom user experience during installation, including custom
dialog boxes for security and maintenance operations. To perform
installation operations, the custom installer uses the
InPlaceHostingManager class.

Walkthrough: Creating a Custom Installer for a ClickOnce Application

EDIT

I am not sure whether you could achieve what you want exactly in the way that you have described in the question. Check whether these threads help you.

Accessing Local and Remote Data in ClickOnce Applications

How to include custom data files in ClickOnce deployment?

How to: Retrieve Query String Information in an Online ClickOnce Application

深海里的那抹蓝 2024-12-09 12:41:26

您如何想象在下载时“重写”setup.exe?如果用户不是使用提供的链接 (url) 打开应用程序,而是直接从网络共享本地下载文件,则您无法拦截此行为。

我会尝试使用权限并让用户从提供给他们的链接执行它,但无法直接连接到共享或网址并下载它。无论如何,不​​确定这是否可能。

How would you imagine to "rewrite" setup.exe at download? if instead of opening your application with the provided link (url) users are downloading the file locally directly from the network share, you can't intercept this.

I would try to play with permissions and have the users to execute it from the link provided to them, but unable to connect directly to the share or web address and download it. Not sure this is possible anyway.

仙女山的月亮 2024-12-09 12:41:26

您可以尝试将该信息作为资源嵌入到 exe 中。
下面是更新 exe 资源的 C++ 示例。 http://msdn.microsoft.com/ en-us/library/ms648008(v=vs.85).aspx#_win32_Updating_Resources

You can try embedding that information as a resource into the exe.
Here's a c++ example of updating a resource of an exe. http://msdn.microsoft.com/en-us/library/ms648008(v=vs.85).aspx#_win32_Updating_Resources

书间行客 2024-12-09 12:41:26

您应该结合 Charith 和 Josh 的方法 - 本质上是配置您的 Web 服务器,以便您可以根据 URL 参数生成新的设置。使用自定义安装程序从 setup.exe 资源中读取引用信息。检查此链接了解如何在 C# 中操作本机应用程序的资源 - 您必须在生成安装程序时写入资源文件,并且需要从自定义安装程序中读取它。

生成自定义设置的另一种方法是从嵌入必要信息的命令行构建可执行文件或帮助程序集。然后从命令行工具构建设置(请参阅 http://msdn.microsoft. com/en-us/library/xc3tc5xx.aspx)。与修改已构建的设置的资源相比,它似乎相当麻烦,并且需要很长时间才能生成自定义设置。

一种完全不同的方法是每当用户下载应用程序时通过电子邮件发送唯一的推荐代码(注册代码)。在安装程序(或应用程序)中,使用自定义安装程序提示用户输入此代码。如果通过 URL 调用安装程序,则可以从那里获得代码,在这种情况下,自定义安装程序不需要请求代码。用户下载安装程序时发送的电子邮件应通知用户将代码与安装文件一起保存到某个文本文件中。

You should combine approach by Charith and Josh - essentially, configure your web server so that you can generate a new setup based on URL parameters. Use custom installer to read from the referral information from resource for setup.exe. Check this link for how to manipulate resources for a native application in C# - you have to write to resource file while generating setup and need to read it from your custom installer.

Yet another way of generating custom setup would be to build your executable or helper assemblt from command line embedding the necessary information. And then build the setup from command line tools (see http://msdn.microsoft.com/en-us/library/xc3tc5xx.aspx). It appears to be quite cumbersome and will take long time to generate the custom setup as opposed to modifying the resource of already built setup.

A completely different approach would be to email the unique referral code (registration code) whenever user downloads the application. In the setup (or application), use custom installer to prompt user for this code. If the setup is invoked via URL then the code will be available from there and in such case Custom Installer need not ask for the code. The email that you send when user download the setup should inform user to preseve the code into some text file along with the setup file.

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