如何运行 WHERE 中有属性的程序

How to run the program with attribute in WHERE

我需要搜索并 运行cmd 中的程序 windows 7. 我尝试了以下代码,当一起键入时它似乎没有拾取操作符。

START WHERE /R C:\ Program.exe /uninstall
dir /s /b Program.exe /uninstall

是否有另一种 (simpler/better) 方式来使用运算符启动程序?

where 搜索文件,但不执行它们。 start where 除了在新的 cmd 实例中启动 where 之外什么都不做,因此 startwhere 相关,但与 where 搜索的文件无关。

dir 列出目录内容,但也不执行任何内容。实际上你应该使用 dir /S /B C:\Program.exeC:\ 中搜索 Pogram.exe;请注意 dir /S /B Program.exe 在当前工作目录中搜索 Program.exe(递归)。

如您所述,/uninstall 开关被视为 wheredir 命令行的一部分。

您需要将任务分为两个阶段:

  1. 正在 C:\ 中递归搜索文件 Program.exe
  2. 正在使用选项 /uninstall;
  3. 执行文件 Program.exe

以下是它如何使用 where:

for /F "delims=" %%E in ('where /R "C:\" "Program.exe"') do (
    "%%E" /uninstall
)

这是一种使用 dir 的方法(/A:-D 选项已添加到非 return 目录 称为 Program.exe ):

for /F "delims=" %%E in ('dir /S /B /A:-D "C:\Program.exe"') do (
    "%%E" /uninstall
)

如果C:\中还有更多名为Program.exe的文件,则全部执行。