问题描述
我想读MSI文件到MemoryStream(或类似的东西),并对其进行修改。怎样做最简单的方法,而不会破坏MSI?
我只需要能够做的就是修改微星的属性之一的价值。我想美元的净p $ PFER的东西,但我开到其他平台。
更新:
这是我的工作code,使用Windows平台的SDK,一个COM引用Microsoft Windows安装程序对象库和命名空间WindowsInstaller:
安装程序安装= Activator.CreateInstance(Type.GetTypeFromProgID(WindowsInstaller.Installer))的安装程序;
数据库MSI = installer.OpenDatabase(WixTest.msi,MsiOpenDatabaseMode.msiOpenDatabaseModeTransact);
查看查看= msi.OpenView(更新`Property` SET`Property`.`Value` = '99'在哪里'Property` ='USERID');
view.Execute(空);
msi.Commit();
检查出的,还有包括在使用的。
下面是一个命令行的一个简化版本的VBScript我用它来做到这一点:
显式的选项
常量msiOpenDatabaseModeReadOnly = 0
常量msiOpenDatabaseModeTransact = 1
昏暗的openMode:的openMode = msiOpenDatabaseModeTransact
昏暗的argCount:argCount = Wscript.Arguments.Count
如果(argCount 3;)然后WScript.Echo用法:msisetproperty.vbs< MSI><性><价值>中:WScript.Quit 1
昏暗MY_MSI:MY_MSI = Wscript.Arguments(0)
昏暗sProp1:sProp1 = Wscript.Arguments(1)
昏暗sVal1:sVal1 = Wscript.Arguments(2)
昏暗的filesys:设置的filesys =的CreateObject(Scripting.FileSystemObject的)
如果不filesys.FileExists(MY_MSI)然后WScript.Echo无法找到微星,退出:WScript.Quit 1
昏暗的安装程序,数据库,视图结果
设置安装=的CreateObject(WindowsInstaller.Installer)
昏暗sumInfo:设置sumInfo = installer.SummaryInformation(MY_MSI,0)
设置数据库= installer.OpenDatabase(MY_MSI,的openMode)
设置视图= database.OpenView(UPDATE属性设置值='&放大器; sVal1&安培;'凡财产='&放大器; sProp1&安培;')
view.Execute
database.Commit
设置数据库=什么
I'd like to read an MSI file into a MemoryStream (or something similar), and modify it. What's the easiest way to do this, without corrupting the MSI?
All I need to be able to do is modify the value of one of the properties in the MSI. I'd prefer something in .Net, but I'm open to other platforms.
Update:
Here's my working code, using the Windows platform SDK, a COM reference to Microsoft Windows Installer Object Library and namespace WindowsInstaller:
Installer installer = Activator.CreateInstance(Type.GetTypeFromProgID("WindowsInstaller.Installer")) as Installer;
Database msi = installer.OpenDatabase("WixTest.msi", MsiOpenDatabaseMode.msiOpenDatabaseModeTransact);
View view = msi.OpenView("update `Property` SET `Property`.`Value`='99' where `Property`='USERID'");
view.Execute(null);
msi.Commit();
Check out the Windows SDK, there are a bunch of samples included on using the Windows Installer API.
Here's a simplified version of a command line VBScript I use to do this:
Option Explicit
Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1
Dim openMode : openMode = msiOpenDatabaseModeTransact
Dim argCount:argCount = Wscript.Arguments.Count
If (argCount < 3) Then WScript.Echo "usage: msisetproperty.vbs <msi> <property> <value>" : WScript.Quit 1
Dim MY_MSI : MY_MSI = Wscript.Arguments(0)
Dim sProp1 : sProp1 = Wscript.Arguments(1)
Dim sVal1 : sVal1 = Wscript.Arguments(2)
Dim filesys : Set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FileExists(MY_MSI) Then WScript.Echo "Unable to find msi, exiting" : WScript.Quit 1
Dim installer, database, view, result
Set installer = CreateObject("WindowsInstaller.Installer")
Dim sumInfo : Set sumInfo = installer.SummaryInformation(MY_MSI, 0)
Set database = installer.OpenDatabase (MY_MSI, openMode)
Set view = database.OpenView ("UPDATE Property SET Value='" & sVal1 & "' WHERE Property='" & sProp1 & "'")
view.Execute
database.Commit
Set database = nothing
这篇关于我怎样才能修改微星在内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!