使用Winrar制作简易安装包

Authors:Larry@ www.joyglue.com
Version:1.0

生成安装包的批处理bat

Python setup.py build
copy check.ps1 build\somedir
rar a -m5 -ep1 -r -sfx -z"install.conf" targetfile.exe artefacts\*

install.conf的内容

;comments
Setup=install.bat ;解压后执行
Title=promgram title
Text
{
some explain for this software
}
License=授权
{
license information
}
Shortcut=D,programname.exe   ;桌面快捷方式
Path=somepath; 默认解压路径到program files

安装包中自动运行的install.bat

在解压完成后,自动运行install.bat:

powershell -ExecutionPolicy Bypass -file "./check.ps1"

使用Powershell环境检查

检查脚本文件命名为check.ps1:

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
<# this is comments
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$result = Get-WmiObject Win32_QuickFixEngineering | Where-Object {$_.HotFixID -eq "KB*"}
#>
$result = Get-Hotfix -Id "KB*" -ErrorAction SilentlyContinue
if($result)
{
$text = "hello ok."
[System.Windows.Forms.MessageBox]::Show($text,"sys check",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information)
}else
{
...
}

Winrar不足

Winrar并不是专业安装包制作工具,没有强大的功能,也有很多bug,例如安装进行当中关闭安装界面,桌面 仍然会产生快捷方式。另外在win7以上系统上,会自动进行UAC提权,造成安装时候的账号权限和使用时候的 账号权限不同,从而产生运行问题。

对此,我们可以使用windows 比较专业的安装包制作工具:inno setup