最近在维护之前一些VS 2005自带的安装包工程做了msi的安装包
发现在Custom Action中执行一些exe等 没有获得Admin权限,导致操作失败。
经过网上搜索解决方案发现,需要修改属性,但是这些属性需要用Custom Action
msi 很多属性要靠js脚本来添加:
下面来看一段添加Custom Action使用admin权限的脚本
// Usage: CustomAction_NoImpersonate.js <msi-file> // Performs a post-build fixup of an MSI to change all // deferred custom actions to include NoImpersonate // Constant values from Windows Installer var msiOpenDatabaseModeTransact = 1; var msiViewModifyInsert = 1 var msiViewModifyUpdate = 2 var msiViewModifyAssign = 3 var msiViewModifyReplace = 4 var msiViewModifyDelete = 6 var msidbCustomActionTypeInScript = 0x00000400; var msidbCustomActionTypeNoImpersonate = 0x00000800 if (WScript.Arguments.Length != 1) { WScript.StdErr.WriteLine(WScript.ScriptName + " file"); WScript.Quit(1); } var filespec = WScript.Arguments(0); var installer = WScript.CreateObject("WindowsInstaller.Installer"); var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact); var sql var view var record try { sql = "SELECT `Action`, `Type`, `Source`, `Target` FROM `CustomAction`" view = database.OpenView(sql); view.Execute(); record = view.Fetch(); while (record) { if (record.IntegerData(2) & msidbCustomActionTypeInScript) { record.IntegerData(2) = record.IntegerData(2) | msidbCustomActionTypeNoImpersonate; view.Modify(msiViewModifyReplace, record); } record = view.Fetch(); } view.Close(); database.Commit(); } catch(e) { WScript.StdErr.WriteLine(e); WScript.Quit(1); }
PS:如果你不知道如何使用Js,请参考:
Here are the instructions that can be used to modify an MSI built in VS 2005 to set the NoImpersonate attribute for all deferred custom actions:
下面是通过JS来实现 msi安装包安装完成后重启系统的功能
Option Explicit Const msiOpenDatabaseModeTransact = 1 Dim msiPath : msiPath = Wscript.Arguments(0) Dim installer Set installer = Wscript.CreateObject("WindowsInstaller.Installer") Dim database Set database = installer.OpenDatabase(msiPath, msiOpenDatabaseModeTransact) Dim query query = "INSERT INTO Property(Property, Value) VALUES('REBOOT', 'Force')" Dim view Set view = database.OpenView(query) view.Execute database.Commit
让安装包安装后不会在控制面板中出现卸载的js脚本
Option Explicit Const msiOpenDatabaseModeTransact = 1 Dim msiPath : msiPath = Wscript.Arguments(0) Dim installer Set installer = Wscript.CreateObject("WindowsInstaller.Installer") Dim database Set database = installer.OpenDatabase(msiPath, msiOpenDatabaseModeTransact) Dim query query = "INSERT INTO Property(Property, Value) VALUES('ARPSYSTEMCOMPONENT', '1')" Dim view Set view = database.OpenView(query) view.Execute database.Commit
常见MSI安装包中的属性:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa367750(v=vs.85).aspx