windows 批处理文件以静默方式安装多个程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29888954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:02:23  来源:igfitidea点击:

Batch file to install multiple programs silently

windowsbatch-file

提问by Gaurang

I want to create a batch file which will install multiple programs sequentially. I am able to install the required softwares sequentially using following code in batch file:

我想创建一个批处理文件,它将按顺序安装多个程序。我可以使用批处理文件中的以下代码按顺序安装所需的软件:

@echo off
"Path/software1.exe"
"Path/software2.exe"
"Path/software3.exe"
"Path/software4.exe"

OR

或者

@echo off
start /wait "Path/software1.exe"
start /wait "Path/software2.exe"
start /wait "Path/software3.exe"
start /wait "Path/software4.exe"

But here before installing any software I want to check if it is already installed or not.

但是在安装任何软件之前,我想检查它是否已经安装。

I have tried getting the list of installed softwares using following two ways:

我尝试使用以下两种方式获取已安装软件的列表:

wmic product get name

OR

或者

reg export HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall temp.txt /y

But then I would have to search strings which isn't feasible. Thus I would like to know if their is any command to check if a particular application is installed or not using a batch file? Thanks in advance.

但随后我将不得不搜索不可行的字符串。因此,我想知道他们是否有任何命令来检查是否安装了特定应用程序或不使用批处理文件?提前致谢。

回答by selbie

There's no formal way to check to see if an application is installed. Installers, for the most part, just copy files, set registry keys, and add start menu shortcuts without registering anything with Windows to say, I'm installed.

没有正式的方法来检查是否安装了应用程序。在大多数情况下,安装程序只需复制文件、设置注册表项和添加开始菜单快捷方式,而无需在 Windows 中注册任何内容,也就是说,我已安装。

A generic way to see if an application is installed is to see if it has an entry in the Add/Remove Programs applet of Control Panel. Each entry in the ARP is found in the registry at : Software\Microsoft\Windows\CurrentVersion\Uninstall(of both HKEY_CURERNT_USER and HKEY_LOCAL_MACHINE)

查看应用程序是否已安装的通用方法是查看它是否在控制面板的添加/删除程序小程序中有条目。ARP 中的每个条目都在注册表中找到: Software\Microsoft\Windows\CurrentVersion\Uninstall(HKEY_CURRNT_USER 和 HKEY_LOCAL_MACHINE)

If it is MSI based installer, then you probably can write some code to see if the Feature ID or Component ID is installed with the MSI API. I wouldn't know how to invoke those functions in a BAT file without compiling some helper programs.

如果它是基于 MSI 的安装程序,那么您可能可以编写一些代码来查看 Feature ID 或 Component ID 是否与MSI API一起安装。如果不编译一些帮助程序,我不知道如何在 BAT 文件中调用这些函数。

回答by Sourav Ghadai

you just take conditions

你只需要条件

if not exist "C:\Program Files\software1"
"Path/software1.exe"

如果不存在 "C:\Program Files\software1"
"Path/software1.exe"

if not exist "C:\Program Files\software2"
"Path/software2.exe"

如果不存在 "C:\Program Files\software2"
"Path/software2.exe"

if not exist "C:\Program Files\software3"
"Path/software3.exe"

如果不存在 "C:\Program Files\software3"
"Path/software3.exe"

if not exist "C:\Program Files\software4"
"Path/software4.exe"

如果不存在 "C:\Program Files\software4"
"Path/software4.exe"

回答by JB_techwiz

This may help (which I use to help show installed software following a completed batch) is to put "appwiz.cpl" without quotations at the end of your script.

这可能有助于(我用它来帮助显示完成批处理后已安装的软件)是在脚本末尾放置不带引号的“appwiz.cpl”。

example:

例子:

@echo off
C:\WINDOWS\system32>
cd C:/ (assuming files are located here)
echo You are about to install software1,2,3, press ENTER to proceed...
pause
"path\software1.exe"
"path\software2.exe"
"path\software3.exe"
appwiz.cpl