windows 如何从命令行添加/更新 MSI 内的属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1609250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I add/update a property inside an MSI from the command-line?
提问by Jason Cohen
I have an MSI installer in which I need to add or modify a short text property from the command-line.
我有一个 MSI 安装程序,我需要在其中从命令行添加或修改一个短文本属性。
This has to be done after the installer is built; I cannot modify the process that produces the installer in the first place. It also has to be executed headless from a script.
这必须在构建安装程序之后完成;我无法首先修改生成安装程序的过程。它也必须从脚本中无头执行。
When I say "property," it could be an MSI property, a value that gets written to the registery at install-time, or any other mechanism that can get this short custom text into the installed application when it runs.
当我说“属性”时,它可能是一个 MSI 属性、一个在安装时写入注册表的值,或者任何其他可以在已安装的应用程序运行时将此简短的自定义文本导入到已安装应用程序中的机制。
回答by saschabeaumont
Example VBScript that you could use to update (or add) a property post-build...
可用于在构建后更新(或添加)属性的示例 VBScript...
Option Explicit
Const MSI_FILE = "myfile.msi"
Dim installer, database, view
Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase (MSI_FILE, 1)
' Update
Set view = database.OpenView ("UPDATE Property SET Value = '" & myproperty & "' WHERE Property = 'MYPROPERTY'")
' .. or Add (Insert)
Set view = database.OpenView ("INSERT INTO Property (Property, Value) VALUES ('MYPROPERTY', '" & myproperty & "')")
view.Execute
Set database = Nothing
Set installer = Nothing
Set view = Nothing
For more information check out the Windows Installer SDK (part of the Windows SDK), there's a bunch of example scripts that you can use from the command line to do various MSI manipulation tasks, for example WiRunSQL.vbs
lets you execute arbitrary SQL against an MSI.
有关更多信息,请查看 Windows Installer SDK(Windows SDK 的一部分),这里有一堆示例脚本,您可以从命令行使用它们来执行各种 MSI 操作任务,例如WiRunSQL.vbs
让您针对 MSI 执行任意 SQL。
回答by ZippyV
c:\> msiexec /i yourmsi.msi THEPROPERTYNAME=valueofproperty
For more information type msiexec at the commandline.
有关更多信息,请在命令行中键入 msiexec。
EDIT: or change the .msi file itself by using sql statements and updating the property in the properties table: http://msdn.microsoft.com/en-us/library/aa372021(VS.85).aspxhttp://msdn.microsoft.com/en-us/library/aa368568(VS.85).aspx
编辑:或通过使用 sql 语句并更新属性表中的属性来更改 .msi 文件本身: http: //msdn.microsoft.com/en-us/library/aa372021(VS.85).aspx http:// msdn.microsoft.com/en-us/library/aa368568(VS.85).aspx
回答by asarenski
This is to add to @saschabeaumont 's answer in '09. Currently using dotNet 4.0
这是添加到@saschabeaumont 在 09 年的回答中。目前使用 dotNet 4.0
Option Explicit
Const MSI_FILE = "myFilePath.msi"
Const PROPERTY_STRING_Value = "FooBar"
Dim installer, database, view
Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase (MSI_FILE, 1)
' Update
Set view = database.OpenView ("UPDATE Property SET Value = '" & PROPERTY_STRING_Value & "' WHERE Property = 'MYPROPERTY'")
' .. or Add (Insert)
Set view = database.OpenView ("INSERT INTO Property (Property, Value) VALUES ('MYPROPERTY', '" & PROPERTY_STRING_Value & "')")
view.Execute()
database.Commit()
Set database = Nothing
Set installer = Nothing
Set view = Nothing