我想使用powershell添加一个从二进制表调用VBScript的自定义操作。 我到处搜索找到PowerShell代码,这一切似乎都是VBScript。我曾尝试自己做,但总是错误。 有没有人能够使用PowerShell将文件添加到二进制表? 非常感谢任何帮助。 这是我到目前为止: 这是我到目前为止的代码: VBScript
Dim query
query="INSERT INTO `Binary` (`Name`, `Data`) VALUES ('NewBlob', ?)"
Set Installer = CreateObject("WindowsInstaller.Installer")
Set Record = Installer.CreateRecord(1)
Record.SetStream 1, "C:\Users\Admin\Desktop\coder\CA_Test.vbs"
Set Database = Installer.OpenDatabase("C:\Users\Admin\Desktop\7z920.msi", 1)
Set View = Database.OpenView(query)
View.Execute Record
Database.Commit
Powershell的
$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$database1 = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase",
"InvokeMethod",
$Null,
$windowsInstaller,
@($database1Path, $msiOpenDatabaseModeReadOnly)
)
$database2 = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase",
"InvokeMethod",
$Null,
$windowsInstaller,
@($database2Path, $msiOpenDatabaseModeTransact)
)
$query = "INSERT INTO ``Binary``(``Name``,``Data``) VALUES ('Callsetstatuskey', ?)"
$View = $database2.GetType().InvokeMember(
"OpenView",
"InvokeMethod",
$Null,
$database2,
($query)
)
$Record = $windowsInstaller.GetType().InvokeMember ("CreateRecord", "InvokeMethod", $Null, $windowsInstaller, 1)
$Record.GetType().InvokeMember("SetStream", "InvokeMethod", $Null, $windowsInstaller.Record, @($SetstausKeyPath, 1))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Record)
$View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($View) | Out-Null
powershell脚本中有很多代码创建功能,组件添加注册表项属性和自定义操作。除了在二进制表中添加文件外,一切都很好。
谢谢, 吉姆
答案 0 :(得分:0)
吉姆,我想我已在这里回答了你的问题:http://www.alkanesolutions.co.uk/2017/02/10/write-windows-installer-binary-stream-using-powershell/
$query = "INSERT INTO `Binary` (`Name`,`Data`) Values(?,?)"
$View = $database2.GetType().InvokeMember("OpenView","InvokeMethod",$Null,$database2,($query))
$binaryrecord = $windowsInstaller.GetType().InvokeMember("CreateRecord", "InvokeMethod", $null, $windowsInstaller, 2)
$binaryrecord.GetType().InvokeMember("StringData", "SetProperty", $null, $binaryrecord, @(1, "AlkaneBinary"))
$fileToStream = "C:\Alkane\AlkaneFile.txt"
$binaryrecord.GetType().InvokeMember("SetStream","InvokeMethod", $null, $binaryrecord, @(2, $fileToStream))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $binaryrecord)
$View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($View) | Out-Null
感谢。