[英]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.