简体   繁体   English

从批处理文件执行时 MSI 安装程序不安装

[英]MSI installer does not install when executed from a batch file

I am currently creating an improvised installer for a cople software packages.我目前正在为一个复杂的软件包创建一个临时安装程序。 To do this I have to install a couple MSI packages first before doing a couple file operations.为此,我必须先安装几个 MSI 包,然后再进行几个文件操作。

To install an MSI package I am using the following command:要安装 MSI 包,我使用以下命令:

start /wait msiexec /i "Myinstaller V2.1.msi" /qb

This command works and installs the package instantly and witout any problems via CMD.此命令可以立即运行并通过 CMD 安装包,不会出现任何问题。

But when I put this command in my batch file and execute it as an administrator, I get the following error: This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package但是当我把这个命令放在我的批处理文件中并以管理员身份执行时,我得到以下错误: This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package

What cold be the problem?什么冷的问题? Using the same command via the console works flawlessly, only the batch file throws the error...通过控制台使用相同的命令可以完美地工作,只有批处理文件会抛出错误...

EDIT: I have also tried the /a parameter in order to install it as an administrator and it does not work either.编辑:我也尝试过/a参数以便以管理员身份安装它,但它也不起作用。 Full command in batch file:批处理文件中的完整命令:

start /wait msiexec /qn /a "Myinstaller V2.1.msi"

EDIT2: I just realized that it only does not work when I start the batch file with Right click > Run as administrator When I open a console with administrative rights and start my batch file it works for some reason... EDIT2:我刚刚意识到只有当我使用Right click > Run as administrator启动批处理文件时它才不起作用当我打开具有管理权限的控制台并启动我的批处理文件时,它出于某种原因工作......

Is there a way to make it work with the Right click > Run as administrator method?有没有办法让它与Right click > Run as administrator方法一起使用?

SOLUTION: Thanks to RGuggisberg's answer I now know that the directory changes once the file is executed as an administrator .解决方案:感谢 RGuggisberg 的回答,我现在知道一旦文件以管理员身份执行,目录就会发生变化 With a small change the installer gets fired up as an admin and works perfectly starting the installer from a relative path in the same directory:通过一个小的更改,安装程序将以管理员身份启动,并且可以完美地从同一目录中的相对路径启动安装程序:

@echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
pause

I've now also implemented a feature to detect wether or not the installation fails or not:我现在还实现了一项功能来检测安装是否失败:

@echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
if %ERRORLEVEL% EQU 0 echo SUCCESSFULL 
if NOT %ERRORLEVEL% EQU 0 echo MyProgram installation FAILED
pause

The current directory changes when you run as administrator.当您以管理员身份运行时,当前目录会发生变化。 If you want to prove that to yourself, see this post Difference between "%~dp0" and ".\"?如果您想向自己证明这一点,请参阅这篇文章“%~dp0”和“.\”之间的区别? Include the full path to your filename and it will work.包括文件名的完整路径,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调试从 Inno Setup 安装程序执行的非工作批处理文件或命令 - Debugging non-working batch file or command executed from Inno Setup installer 安装 MSI 的批处理脚本 - Batch script to install MSI 从另一个批处理文件调用该批处理文件时,批处理文件中的复制命令未得到执行,但是当我双击时,该命令正在执行 - copy command in batch file is not getting executed when calling the batch file from another batch file, but is getting executed when i double click 如何将批处理/预安装命令行附加到Advanced Installer msi? - How to attach batch/pre-install command line to Advanced Installer msi? 从同一位置的批处理文件执行.msi - Executing the .msi from batch file in same location 不从批处理文件执行for循环 - For loop is not executed from batch file 从批处理文件执行时 ICACLS 表现怪异 - ICACLS behaving weird when executed from batch file 从隐藏窗口的c#执行批处理文件时,该批处理文件执行的程序将无法启动 - When executing a batch file from c# with the window hidden, programs that are executed by the batch file won't start 执行批处理文件时出现一个随机括号 - A random bracket appeares when the batch file is executed 执行批处理文件时没有任何反应 - nothing happens when the batch file is executed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM