我可以在 setup.msi 之前 运行 命令吗?
Can I run a command before the setup.msi?
我有一个桌面应用程序,它的安装程序项目在 Release
文件夹中生成了两个文件:我们称它们为 setup.exe
和 setup.msi
.
在 post 构建事件中,我使用自签名证书签署了 setup.msi
。那么我最终的安装批次由三步组成
- 添加带有
start.cmd
(或 start.exe
)的用户存储证书
- 运行
setup.exe
。请注意,重要的是它显示了一个 已验证 作者的用户帐户控件,其中包含我的名字和姓氏。
- 删除(使用
stop.cmd
或 stop.exe
)第 1 点的证书以确保安全 reasons/best 做法,因为它是自签名的
现在我对这个解决方案非常满意,我只希望在 setup.exe
中包含命令 1 和 3,如果可以以标准方式实现的话。
我试图做的是将 start.exe
和 stop.exe
定义为自定义操作。在那种情况下,我只有 setup.exe
和 setup.msi
这两个文件,但不幸的是我得到了一个 unkown 发布者。我想这显然是因为自定义操作在 .msi
中而不是在 setup.exe
中。但我不是安装程序项目的专家,所以有人可能会建议更好的标准解决方案。
替代方法
我可以通过切换到 Inno Setup 更轻松地做到这一点吗?也许正如本文 comment 中所建议的那样?
参考资料
更新答案
抱歉,我已经在下面测试了我的原始答案,它在某种意义上是 "wrong":
实际上我得到了一个单击安装程序,但是 Windows 操作系统在这种单击安装程序之前预期了用户帐户控制,并且它显示了一个未知的发布者,这违背了第 1 点(和第 3 点)的目的.
所以,简短,更新的答案:不可能(*)在标准的单击 exe 中执行此操作,就像下面提到的 SFX 模块生成的那样。
(注 *):尽管可以通过编译自定义 C# 代码并将文件添加到 Resources.resx
,例如 _7zr.exe
,等等...就像这个例子:
using System.IO;
using System.Diagnostics;
namespace selfextractinstaller
{
class Program
{
static void Main(string[] args)
{
string file_path_7zr = @"_7zr.exe";
using (FileStream fs = new FileStream(file_path_7zr, FileMode.Create))
{
byte[] pgm_bytes = Properties.Resources._7zr;
fs.Write(pgm_bytes, 0, (int)pgm_bytes.Length);
}
string file_path_config = @"config.txt";
using (StreamWriter sw = new StreamWriter(file_path_config, false))
{
sw.Write(Properties.Resources.config);
}
string file_path_7zSD = @"_7zSD.sfx";
using (FileStream fs = new FileStream(file_path_7zSD, FileMode.Create))
{
byte[] pgm_bytes = Properties.Resources._7zSD;
fs.Write(pgm_bytes, 0, (int)pgm_bytes.Length);
}
Process.Start(file_path_7zr, "b");
}
}
}
类似的代码实际上可以用作自解压安装程序,未提升并且不需要UAC!
进一步阅读
- How does Windows decide whether to display the UAC prompt?
- How do I add a manifest to an executable using mt.exe?
原回答
在没有其他答案的情况下,我将继续 SFX module for installers,将所有三个 .exe
打包在第 1-3 点(加上 install_all.bat
运行按顺序将它们)放入自解压安装程序中,它将自动提取所有需要的文件(包括证书),最后 运行 install_all.bat
我有一个桌面应用程序,它的安装程序项目在 Release
文件夹中生成了两个文件:我们称它们为 setup.exe
和 setup.msi
.
在 post 构建事件中,我使用自签名证书签署了 setup.msi
。那么我最终的安装批次由三步组成
- 添加带有
start.cmd
(或start.exe
)的用户存储证书 - 运行
setup.exe
。请注意,重要的是它显示了一个 已验证 作者的用户帐户控件,其中包含我的名字和姓氏。 - 删除(使用
stop.cmd
或stop.exe
)第 1 点的证书以确保安全 reasons/best 做法,因为它是自签名的
现在我对这个解决方案非常满意,我只希望在 setup.exe
中包含命令 1 和 3,如果可以以标准方式实现的话。
我试图做的是将 start.exe
和 stop.exe
定义为自定义操作。在那种情况下,我只有 setup.exe
和 setup.msi
这两个文件,但不幸的是我得到了一个 unkown 发布者。我想这显然是因为自定义操作在 .msi
中而不是在 setup.exe
中。但我不是安装程序项目的专家,所以有人可能会建议更好的标准解决方案。
替代方法
我可以通过切换到 Inno Setup 更轻松地做到这一点吗?也许正如本文 comment 中所建议的那样?
参考资料
更新答案
抱歉,我已经在下面测试了我的原始答案,它在某种意义上是 "wrong":
实际上我得到了一个单击安装程序,但是 Windows 操作系统在这种单击安装程序之前预期了用户帐户控制,并且它显示了一个未知的发布者,这违背了第 1 点(和第 3 点)的目的.
所以,简短,更新的答案:不可能(*)在标准的单击 exe 中执行此操作,就像下面提到的 SFX 模块生成的那样。
(注 *):尽管可以通过编译自定义 C# 代码并将文件添加到 Resources.resx
,例如 _7zr.exe
,等等...就像这个例子:
using System.IO;
using System.Diagnostics;
namespace selfextractinstaller
{
class Program
{
static void Main(string[] args)
{
string file_path_7zr = @"_7zr.exe";
using (FileStream fs = new FileStream(file_path_7zr, FileMode.Create))
{
byte[] pgm_bytes = Properties.Resources._7zr;
fs.Write(pgm_bytes, 0, (int)pgm_bytes.Length);
}
string file_path_config = @"config.txt";
using (StreamWriter sw = new StreamWriter(file_path_config, false))
{
sw.Write(Properties.Resources.config);
}
string file_path_7zSD = @"_7zSD.sfx";
using (FileStream fs = new FileStream(file_path_7zSD, FileMode.Create))
{
byte[] pgm_bytes = Properties.Resources._7zSD;
fs.Write(pgm_bytes, 0, (int)pgm_bytes.Length);
}
Process.Start(file_path_7zr, "b");
}
}
}
类似的代码实际上可以用作自解压安装程序,未提升并且不需要UAC!
进一步阅读
- How does Windows decide whether to display the UAC prompt?
- How do I add a manifest to an executable using mt.exe?
原回答
在没有其他答案的情况下,我将继续 SFX module for installers,将所有三个 .exe
打包在第 1-3 点(加上 install_all.bat
运行按顺序将它们)放入自解压安装程序中,它将自动提取所有需要的文件(包括证书),最后 运行 install_all.bat