从 Windows Installer 自定义操作执行脚本文件 [英] Executing a script file from a Windows Installer Custom Action

查看:47
本文介绍了从 Windows Installer 自定义操作执行脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Windows 安装程序项目(标准 OOTB VS 2008 安装程序项目-vdproj)中执行批处理文件作为卸载过程的一部分.无法直接从安装程序项目中的自定义操作执行 bat 文件,因此我编写了一个快速的 vbs 脚本来调用所需的 bat 文件.
vbs 代码:

Set WshShell = WScript.CreateObject("WScript.Shell")command = "卸载-windows-serivce.bat"msgbox 命令WshShell.Run ("cmd/C" & """" & command & """")设置 WshShell = 无

当这个脚本独立于卸载运行时,它工作得很好.但是,当作为卸载的一部分运行时,它不会执行 bat 文件(但会显示消息框,所以我知道调用了 vbs 文件).没有报告错误(至少我可以说).为什么此脚本不能作为卸载自定义操作"的一部分工作

解决方案

我遇到了同样的问题,问题是你不能在 vbs 文件中调用 WScript - 你只需要调用 CreateObject

即.

Set WshShell = CreateObject("WScript.Shell")command = "卸载-windows-serivce.bat"msgbox 命令WshShell.Run ("cmd/C" & """" & command & """")设置 WshShell = 无

I need to execute a batch file as part of the un-install process in a Windows installer project (standard OOTB VS 2008 installer project-vdproj). One cannot execute a bat file directly from the Custom Actions in the installer project, so I wrote a quick vbs script to call the required bat file.
vbs code:

Set WshShell = WScript.CreateObject( "WScript.Shell" )
command = "uninstall-windows-serivce.bat"
msgbox command
WshShell.Run ("cmd /C " & """" & command & """")
Set WshShell = Nothing

When this script is run independent of the uninstall, it works perfectly. However, when run as part of the uninstall, it does not execute the bat file (but the message box is shown, so I know the vbs file is called). No errors reported (at least that I can tell). Why doesn't this script work as part of the "Uninstall Custom Action"

解决方案

I've run into this same problem and the issue is that you can't call WScript within the vbs file - you will need to JUST call CreateObject

ie.

Set WshShell = CreateObject( "WScript.Shell" )
command = "uninstall-windows-serivce.bat"
msgbox command
WshShell.Run ("cmd /C " & """" & command & """")
Set WshShell = Nothing

这篇关于从 Windows Installer 自定义操作执行脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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