加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows安装程序 – 最简单的解决方案来替代MSI中的一个小文件?

发布时间:2020-12-14 04:33:24 所属栏目:Windows 来源:网络整理
导读:我们的许多客户都可以访问InstallShield,WISE或AdminStudio.这些都不是问题.我希望有一些方法可以为我们的小客户提供商业重新打包工具,这是一个免费提供的一套工具和步骤来进行文件替换. 只需要更换压缩MSI中的单个配置文件,就可以假设目标用户已经安装了Orc
我们的许多客户都可以访问InstallShield,WISE或AdminStudio.这些都不是问题.我希望有一些方法可以为我们的小客户提供商业重新打包工具,这是一个免费提供的一套工具和步骤来进行文件替换.

只需要更换压缩MSI中的单个配置文件,就可以假设目标用户已经安装了Orca,知道如何使用它来自定义属性表(嵌入GPO部署的许可证详细信息),并生成了一个MST文件.

免责声明:这与another question非常相似,但是该线程中的问题和答案都不清楚.

好的,我用自己的回答来回答这个问题,提供了一些很好的小VB脚本,这些脚本都会很重.如原始问题所述,目的是为sysadmin用户提供一个简单的解决方案,以便进行更新/更改.

以下是我目前为客户提供的代码的简化版本

Option Explicit

Const MY_CONFIG = "MyConfigApp.xml"
Const CAB_FILE = "config.cab"
Const MSI = "MyApp.msi"

Dim filesys : Set filesys=CreateObject("Scripting.FileSystemObject")

If filesys.FileExists("temp.tmp") Then filesys.DeleteFile("temp.tmp")
filesys.CopyFile MSI,"temp.tmp"

Dim installer,database,database2,view
Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase ("temp.tmp",1)
Set database2 = installer.OpenDatabase (MSI,1)

If Not filesys.FileExists(MY_CONFIG) Then WScript.Quit 2 ' No config file,abort!

Dim objFile,size,result,seq,objCab

' MakeCab object has been depreciated so we fallback to makecab.exe for with Windows 7
On Error Resume Next ' Disable error handling,for a moment
Set objCab = CreateObject("MakeCab.MakeCab.1") 
On Error Goto 0  ' Turn error handling back on

If IsObject(objCab) Then ' Object creation successful - use XP method   
    objCab.CreateCab CAB_FILE,False,False
    objCab.AddFile MY_CONFIG,filesys.GetFileName(MY_CONFIG)
    objCab.CloseCab
    Set objCab = Nothing
Else ' object creation failed - try Windows 7 method
    Dim WshShell,oExec
    Set WshShell = CreateObject("WScript.Shell")
    Set oExec = WshShell.Exec("makecab " & filesys.GetFileName(MY_CONFIG) & " " & CAB_FILE)
End If

Set objFile = filesys.GetFile(MY_CONFIG)
size = objFile.Size

Set view = database.OpenView ("SELECT LastSequence FROM Media WHERE DiskId = 1")
view.Execute
Set result = view.Fetch
seq = result.StringData(1) + 1 ' Sequence for new configuration file

Set view = database.OpenView ("INSERT INTO Media (DiskId,LastSequence,Cabinet) VALUES ('2','" & seq & "','" & CAB_FILE & "')")
view.Execute

Set view = database.OpenView ("UPDATE File SET FileSize = " & size & ",Sequence = " & seq & ",FileName = 'MYC~2.CNF|MyConfigApp.xml' WHERE File = '" & MY_CONFIG & "'")
view.Execute

database.GenerateTransform database2,"CustomConfig.mst"
database.CreateTransformSummaryInfo database2,"CustomConfig.mst",0
filesys.DeleteFile("temp.tmp")

Set view = nothing
Set installer = nothing
Set database = nothing
Set database2 = nothing
Set filesys = Nothing
WScript.Quit 0

更新:MakeCab.MakeCab.1对象已折旧,代码已更新,现在可以使用Windows 7.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读