如何下载带有用户ID参数的MSI安装程序 [英] How to Download MSI installer with argument for user-id

查看:116
本文介绍了如何下载带有用户ID参数的MSI安装程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET C#应用程序,包装在MSI安装程序中-"myprogram.exe".我有一个PHP网站和一个特定页面,用户可以在其中通过链接下载程序.

我希望能够跟踪.NET应用程序中的某些事件.例如-程序已打开".

将事件发送到我的服务器很容易,但是如何从php服务器获取用户ID,这样我才能知道哪个用户在.NET应用程序上做了什么?

我曾考虑过将参数(用户ID)传递给MSI安装程序,但找不到解决方法.

如何在PHP用户ID和.NET应用之间链接?

说明-

许多人提出使用登录系统来绑定服务器和应用程序.

这确实是最简单的解决方案,但是在我的网站上,我不强迫用户登录以下载该应用程序(也不要求.NET应用程序中的登录详细信息-可选).如果我们不必询问登录详细信息,我认为不应该这样,那么用户的体验会更好(使用该应用程序的步骤要少得多)-用户下载和使用桌面应用程序的机会更大. /p>

考虑当前流量->网页-单击下载-运行-使用该应用 (需要10秒)

使用登录名->网页-注册(确认电子邮件?)-重定向-下载点击-运行-应用程序登录-使用该应用程序 (用户需要60-120秒的时间)

解决方案

从程序登录

最好的方法是让用户使用程序中的相同凭据登录.这样,您的程序可以使用安全的OAuth2身份验证与后端API进行通信.这也使用户可以清楚地知道该程序正在与Internet通信.

在文件名中包含用户ID

另一种方法是在下载过程中将用户ID添加到安装程序的文件名中,并在安装程序运行时将其解压缩.您将必须检查安装程序工具是否允许这样做.另外,仅当您的用户ID是UUID或类似的内容(不想让用户猜测其他ID)时,才执行此操作.

App.config

第三个选项是将用户ID添加到App.config文件中.有两种方法可以做到这一点:

  1. 使用未压缩的App.config创建.msi,并添加具有固定UUID的用户ID设置.您的PHP脚本可以查找UUID并将其替换为.msi二进制文件,然后再发送给用户.查看 MST转换
  2. 下的代码段
  3. 使用自定义的App.config按需构建.msi.仅当您的Web服务器在Windows上运行或您具有可以执行此工作的远程Windows构建服务器时,此方法才起作用.

MST转换

您还可以使用MST转换,并使用与我在 App.config 下针对点1所解释的相同的二进制替换技巧.

对于这两个选项,您都可以使用PHP脚本,该脚本使用二进制安全功能替换安装程序中的值,并将文件作为下载发送给用户:

<?php
$userId = // TODO get userId from the session or database
$data = file_get_contents("./my-installer.msi");
// I would use UUID's for template and userId, this way the size of the installer remains the same after replace
$data = str_replace("{fe06bd4e-4bed-4954-be14-42fb79a79817}", $userId, $data);
// Return the file as download
header("Cache-Control: public"); // needed for i.e.
header('Content-Disposition: attachment; filename=my-installer.msi');
header('Content-Type: application/x-msi');
header("Content-Transfer-Encoding: Binary");
echo $data;
?>

序列号

我能想到的最后一种方法是让程序在首次启动时要求一个序列号,并让您的网站为每个用户生成一个唯一的序列号.

I have a .NET C# application, wrapped inside MSI installer - "myprogram.exe". I have a PHP website and a specific page where user can download the program via a link.

I would like to be able to track certain events on the .NET app. For example - "Program Opened".

It's easy to send events to my server, however how do I grab the user-id from the php server, so I can know which user did what on the .NET app?

I thought about passing an argument (the user-id) to the MSI installer but could not find a way to that.

How do I link between the PHP user-id and the .NET app?

Clarification -

Many people offered to use a login system to bind between the server and app.

This is indeed the easiest solution, however on my website I do not force the user to login to download the app (nor I request login details in the .NET app - its optional). If we dont have to ask for login details, I think we shouldn't, the experience for the user will be much better (far less steps to use the app) - greater chance for the user to download and use the Desktop app.

Consider that current flow is -> Webpage - Download click - Run - Use the app (takes 10 seconds)

With login -> Webpage - Register (confirm email?) - Redirect - Download Click - run - app Login - Use the app (takes 60-120 seconds for the user)

解决方案

Login from the program

The best way is to let the user sign-in with the same credentials in your program. This way, your program can use secure OAuth2 authentication to communicate with your back-end API. This also makes it transparent to the user that the program is communicating with the internet.

Include user-id in filename

An other way is to add the user-id to the filename of the installer during download and extract it when the installer runs. You will have to check if your installer tool allows this. Also, only do this if you user-id's are UUID's or something similar as you don't want the user to guess other id's.

App.config

A third option is to add the user-id to the App.config file. There are two ways to do this:

  1. Create your .msi with App.config uncompressed, add a user-id setting with fixed UUID. Your PHP script can lookup the UUID and replace it in the .msi binary before sending it to the user. See code snippet under MST transform
  2. Build the .msi on demand with the custom App.config. This will only work if your webserver is running on Windows or you have a remote Windows build server that can do this job.

MST transform

You could also use an MST transform and use the same binary replace trick as I've explained for point 1 under App.config.

For both options, you could use a PHP script that uses binary-safe functions to replace the values in the installer and sends the file to the user as a download:

<?php
$userId = // TODO get userId from the session or database
$data = file_get_contents("./my-installer.msi");
// I would use UUID's for template and userId, this way the size of the installer remains the same after replace
$data = str_replace("{fe06bd4e-4bed-4954-be14-42fb79a79817}", $userId, $data);
// Return the file as download
header("Cache-Control: public"); // needed for i.e.
header('Content-Disposition: attachment; filename=my-installer.msi');
header('Content-Type: application/x-msi');
header("Content-Transfer-Encoding: Binary");
echo $data;
?>

Serial number

Last method I can think of is to let the program ask for a serial number on first startup and let your website generate a unique serial number for each user.

这篇关于如何下载带有用户ID参数的MSI安装程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆