MSI Custom Action用管理员权限去执行
2016-04-29 18:10
381 查看
最近在维护之前一些VS 2005自带的安装包工程做了msi的安装包
发现在Custom Action中执行一些exe等 没有获得Admin权限,导致操作失败。
经过网上搜索解决方案发现,需要修改属性,但是这些属性需要用Custom Action
msi 很多属性要靠js脚本来添加:
下面来看一段添加Custom Action使用admin权限的脚本
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:
Copy and paste the code listed below and save it to the directory that contains the Visual Studio project you are working on with the name CustomAction_NoImpersonate.js (or download thesample
script and extract the contents to the project directory)
Open the project in Visual Studio 2005
Press F4 to display the Properties window
Click on the name of your setup/deployment project in the Solution Explorer
Click on the PostBuildEvent item in the Properties window to cause a button labeled “…” to appear
Click on the “…” button to display the Post-build Event Command Line dialog
Add the following command line in the Post-build event command line text box:
cscript.exe “$(ProjectDir)CustomAction_NoImpersonate.js” “$(BuiltOuputPath)”
Build your project in Visual Studio 2005 – now all deferred custom actions will have the NoImpersonate bit set for them
下面是通过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
发现在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:
Copy and paste the code listed below and save it to the directory that contains the Visual Studio project you are working on with the name CustomAction_NoImpersonate.js (or download thesample
script and extract the contents to the project directory)
Open the project in Visual Studio 2005
Press F4 to display the Properties window
Click on the name of your setup/deployment project in the Solution Explorer
Click on the PostBuildEvent item in the Properties window to cause a button labeled “…” to appear
Click on the “…” button to display the Post-build Event Command Line dialog
Add the following command line in the Post-build event command line text box:
cscript.exe “$(ProjectDir)CustomAction_NoImpersonate.js” “$(BuiltOuputPath)”
Build your project in Visual Studio 2005 – now all deferred custom actions will have the NoImpersonate bit set for them
下面是通过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
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- 最后一次说说闭包
- Ajax
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- 异步流程控制:7 行代码学会 co 模块
- ES6 走马观花(ECMAScript2015 新特性)
- JavaScript拆分字符串时产生空字符的原因
- Canvas 在高清屏下绘制图片变模糊的解决方法
- Redux系列02:一个炒鸡简单的react+redux例子
- JavaScript 各种遍历方式详解
- call/apply/bind 的理解与实例分享