WIX安装程序从CustomAction执行vbscript [英] WIX installer execute vbscript from CustomAction

查看:46
本文介绍了WIX安装程序从CustomAction执行vbscript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用WIX安装程序执行V​​BScript.目前,我有WiX配置的这一部分:

I can't execute VBScript using WIX installer. Currently I have this part of WiX config:

<Binary Id='KillThatProcessBinary' SourceFile='KillThatProcess.vbs' />
 <CustomAction Id="KillThatProcessAction"
               Execute="immediate"
               BinaryKey='KillThatProcessBinary'
               VBScriptCall='KillThatProcessFunction'
               Return="check"/>

<InstallExecuteSequence>
    <Custom Action='KillThatProcessAction' Before='InstallValidate'/>
    <ScheduleReboot After="InstallFinalize"/>
</InstallExecuteSequence>

此VBS脚本( KillThatProcess.vbs ):

And this VBS script (KillThatProcess.vbs):

Public Function KillThatProcessFunction()
  Set oShell = WScript.CreateObject("WSCript.shell")
  oShell.run "cmd /C wmic process where ""name like '%java%'"" delete"
  Return 0
End Function

我已经尝试将此脚本插入到CustomAction中(作为innerText),并添加属性:Script ="vbscript".但是什么都没用,每次我收到错误消息-"此Windows Installer软件包都有问题.为此安装所需的脚本无法运行.请与支持人员或软件包供应商联系."

I already try to insert this script into CustomAction (as innerText), and add attribute: Script="vbscript". But nothing works, every time I got the error message - "There is a problem with this Windows Installer package. A script reqired for this install to complete could not be run. Contact your support personnel or package vendor."

以及日志文件中的错误:

And errors in log file:

Error 0x80070643: Failed to install MSI package.
[1A88:2FA4][2018-08-21T14:11:17]e000: Error 0x80070643: Failed to configure per-user MSI package.
[1A88:2FA4][2018-08-21T14:11:17]i319: Applied execute package: LPGateway, result: 0x80070643, restart: None
[1A88:2FA4][2018-08-21T14:11:17]e000: Error 0x80070643: Failed to execute MSI package.

我已经执行了该vbs脚本(不是从安装程序执行的),并且可以正常工作.有人知道我做错了吗?

I already execute this vbs script (not from installer) and it works. Anybody know what I do wrong?

推荐答案

我想总结几个问题:

There are a few issues I want to summarize:

  1. VBA&VBScript函数 :VBScript看起来实际上是VBA,并且在MSI中调用VBScript需要一些调整正确调用VBScript函数.
  2. 重启 :您计划的重启必须具有更好的条件,以避免意外重启.
  3. 进程终止 :您要终止哪个进程?
    • 海拔 :如果升高,则需要执行杀死升高才能成功.您的每用户设置可能未设置为完全提升(因此您通常只能结束以您自己的身份运行的进程).
    • 重启管理器 :由于Windows具有Windows的重启管理器功能,因此通常不需要杀死进程.安装程序尝试使用.尝试解释此功能(查找黄色部分).
  1. VBA & VBScript Functions: That VBScript looks like it is actually VBA and calling VBScript in an MSI requires a bit of tweaking to call VBScript functions properly.
  2. Reboot: The reboot you schedule must get a better condition to avoid unexpected reboots.
  3. Process Kill: What process are you trying to kill?
    • Elevation: If it is elevated you need to run the kill elevated for it to succeed. Your per-user setup is likely not set to elevate at all (so you can generally only end processes running as yourself).
    • Restart Manager: Very often you do not need to kill processes, due to the Restart Manager feature of Windows that Windows Installer tries to use. Attempt to explain this feature (look for yellow sections).


问题1 :必须是VBA脚本而不是VBScript吗?记录:我没见过在VBScript中返回 ?在VBScript中,您可以通过将函数名称设置为等于您要返回的内容来从函数返回,快速示例:


Issue 1: That must be a VBA script and not a VBScript? For the record: I haven't seen return in VBScript? In VBScript you return from a function by setting the function name equal to whatever you want to return, quick sample:

result = IsEmptyString("")
MsgBox CStr(result)

Function IsEmptyString(str)

  If str = "" Then 
     IsEmptyString = True 
   Else 
     IsEmptyString = False
  End If

End Function

注意 :以上只是一个愚蠢的,毫无意义的示例.如需更详尽的检查,请尝试来自ss64.com的IsBlank .VBScript带有 IsEmpty IsNull

Note: The above is just a silly, rather meaningless example. For more elaborate checking try IsBlank from ss64.com. VBScript comes with the functions IsEmpty and IsNull and IsObject.

在MSI文件中使用时,我通常不会在VBScript中添加功能,而是直接运行脚本,因此运行此VBScript应该可以:

When used in MSI files, I normally don't add a function in the VBScript, but just run the script directly, so running this VBScript should work:

MsgBox(Session.Property("ProductName"))

将其插入WiX源(请注意,未指定任何函数调用):

Inserting it into the WiX source (notice no function call specified):

<Binary Id='Sample.vbs' SourceFile='Sample.vbs' />
<CustomAction Id='Sample.vbs' VBScriptCall='' BinaryKey='Sample.vbs' Execute='immediate' Return='ignore'/>

至关重要的是,您的VBScript仍然可以调用同一VBScript文件中可用的其他函数.因此,在上面的示例中,可以从文件顶部的主要无名"功能调用" IsEmptyString ".

Crucially your VBScript can still call other functions available in the same VBScript file. So in the above sample "IsEmptyString" can be called from the main "nameless" function at the top of the file.

检查退出代码 :最后,设置为检查退出代码的任何自定义操作都可以将您的设置置于 abort (立即模式)或回滚(延迟模式).如果自定义操作无法运行,则必须结束设置,我只会检查退出代码.

Check Exit Code: And finally, any custom action set to check exit code can throw your setup into abort (immediate mode) or rollback (deferred mode). I would only check the exit code if you have to end the setup if the custom action can not run.

问题2:重新启动 .我认为这是一个非常严重的问题.我见过人们在大规模部署期间导致意外重启的原因而出门.重新启动知识工作者的PC(及其管理器),同时打开十二个Visual Studio窗口,数十个浏览器窗口以及Word和Excel,然后为它命名.它会引起很多问题.他们可能知道您的住所!:-)

Issue 2: Reboots. This is a very serious issue in my opinion. I have seen people sent out the door for causing unexpected reboots during large scale deployments. Rebooting a knowledge worker's PC (and their managers) with a dozen Visual Studio windows open, dozens of browser windows and Word and Excel and you name it. It can cause a great deal of problems. And they may know where you live! :-)

请阅读以下答案(至少在开始时有3个要点):

Please read the following answer (at least its 3 bullet points at the beginning): Reboot on install, Don't reboot on uninstall

问题3:进程终止 .如上所述,进程的终止与重新启动问题有关.如果进程符合Windows Restart Manager(如上面的链接中所述),则不一定总是要终止进程.在这里让我重复一遍(黄色部分应该为您提供要点,尤其是我认为的第二部分).

Issue 3: Process Kill. As indicated above the killing of processes is related to the reboot issues. It is not always necessary to kill processes if they are compliant with Windows Restart Manager as explained in the link above. Let me repeat it here (yellow sections should give you the gist of it - especially the second one I think).

有几种杀死进程的方法.请注意,最常见的问题可能是您没有杀死该进程的访问权限和/或特权,无论您使用哪种工具或方法来杀死它.

There are a few different ways to kill processes. Note that the most common problem might be that you don't have the access rights and / or privileges to kill the process - no matter what tool or approach you use to do so.

也许您可以从Util模式尝试 CloseApplication功能: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html

Perhaps you can try the CloseApplication feature from the Util schema: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html

  • In Wix MSI: Killing a process upon uninstallation
  • Kill windows service forcefully in WIX (towards bottom)
  • Kill process using WMI / VBScript
  • Some people combine taskill.exe and WiX by means of the Quiet Execution Custom Action (CAQuietExec: hide command line windows). FireGiant documentation.

我不确定建议使用以下哪个选项.我完全不喜欢杀死进程的概念,但是我猜有时候没有其他选择.

I am not sure which of these options to recommend. I don't like the concept of killing processes altogether, but sometimes there is no other option I guess.

这篇关于WIX安装程序从CustomAction执行vbscript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆