在WiX中,我有一个用于自定义操作的vbScript,它将返回网络打印机的ListItems。我想在安装时使用这些ListItem来填充ComboBox,因为在开始安装之前我不会知道用户系统上的打印机名称。
这是vbScript。它目前输出到一个文本文件,等待如何使用它来回答我的问题。
Const ForWriting = 2
Set objNetwork = CreateObject("Wscript.Network")
strName = objNetwork.UserName
strDomain = objNetwork.UserDomain
strUser = strDomain & "\" & strName
strText = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = FALSE")
For Each objPrinter in colPrinters
strText = strText & "<ListItem Text=""" & objPrinter.Name &""" Value="""& objPrinter.Name &"""/>" & vbcrlf
Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile _
("C:\Scripts\Printers.txt", ForWriting, True)
objFile.Write strText
objFile.Close
这是输出:
<ListItem Text="\\xfiles\Canon iR3030 PCL6" Value="\\xfiles\Canon iR3030 PCL6"/>
<ListItem Text="\\xfiles\HP2110" Value="\\xfiles\HP2110"/>
我希望能够将此输出用作我的ComboBox的ListItems。
<Control Type="ComboBox" Property="cboPrinters_Prop" Id="cboPrinters" Width="206" Height="16" X="19" Y="139" ComboList="yes">
<ComboBox Property="cboPrinters_Prop">
<ListItem Text="" Value=""/>
</ComboBox>
</Control>
如果有更好的方法,或者我接近这一切都是错的(我一直想像开发人员一样思考),请随时纠正我。我的皮肤很厚......:)
答案 0 :(得分:3)
正如我怀疑在我原来的帖子结束时,有一种不同的方式,我错了。至少有点。作为WiX的新手,我没有考虑应该将值添加到数据库的事实。鉴于我没有遇到过这个问题,但在我的经历中,我得学习新东西。
所以这就是我在我的ComboBox中显示的值:
1。)上面的脚本被修改为使用集合将适当的值发送到名为ComboBox的数据库表。
2。)使用Orca我添加了ComboBox表。顺便说一下,它只保存用于ListItems的信息,等待它... ComboBoxes。
3.)添加了适当的自定义操作。
4.。)在表单加载之前调用它。
这是vb脚本:
Const ERROR_SUCCESS = 0
Const ERROR_INSTALL_FAILURE = 1603
Const msiViewModifyInsertTemporary = 7
Function LogInfo(msg)
Dim rec
Set rec = Session.Installer.CreateRecord(1)
rec.StringData(0) = msg
LogInfo = Session.Message(&H04000000, rec)
End Function
Function GetNetworkPrinters()
Dim oView, oReccombo
Dim r
LogInfo "INSIDE GetNetworkPrinters"
Set objNetwork = CreateObject("Wscript.Network")
strName = objNetwork.UserName
strDomain = objNetwork.UserDomain
strUser = strDomain & "\" & strName
strText = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = FALSE")
Set oView = Session.Database.OpenView("SELECT * FROM `ComboBox`")
oView.Execute
r = 1
For Each objPrinter in colPrinters
r = r + 1
LogInfo "THE PRINTER NAME IS " & objPrinter.Name
Set oReccombo = Session.Installer.CreateRecord(4)
oReccombo.StringData(1) = "cboPrinters_Prop"
oReccombo.IntegerData(2) = r
oReccombo.StringData(3) = objPrinter.Name
oReccombo.StringData(4) = objPrinter.Name
LogInfo "Made it to the call to insert the record"
oView.Modify msiViewModifyInsertTemporary, oReccombo
Next
oView.Close
GetNetworkPrinters = ERROR_SUCCESS
Set oView = Nothing
End Function
添加二进制条目:
<Binary Id="GetNetworkPrinters" SourceFile="*Enter the full path to the script here* \GetNetworkPrinters.vbs" />
添加自定义操作:
<CustomAction Id="AddPrintersToComboBox" BinaryKey="GetNetworkPrinters" VBScriptCall="GetNetworkPrinters" Execute="immediate" Return="check" HideTarget="no" Impersonate="yes" />
将调用添加到InstallUISequence中的自定义操作和AdminUISequence:
<Custom Action="AddPrintersToComboBox" Before="MaintenanceForm"></Custom>
就是这样......当然,现在需要清理脚本以生成更好的日志信息,并且还需要更好的(某些)错误处理,但它确实有效。
我希望这有助于其他人......