Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 在批处理脚本中使用破折号和开关_Batch File - Fatal编程技术网

Batch file 在批处理脚本中使用破折号和开关

Batch file 在批处理脚本中使用破折号和开关,batch-file,Batch File,我刚刚创建了简单的批处理脚本。我想用“-q”-splash uninstall这样的开关运行uninstall.exe 这是代码; @回音 echo此脚本将卸载某些功能。 暂停 设置路径=C:\Program Files\Program\uninstall.exe-q-splash uninstall 开始“%path%” 暂停 如果运行此代码,则会出现错误: Windows cannot find 'C:\Program Files\Program\uninstall.exe -q -spl

我刚刚创建了简单的批处理脚本。我想用“-q”-splash uninstall这样的开关运行uninstall.exe

这是代码;

@回音
echo此脚本将卸载某些功能。
暂停
设置路径=C:\Program Files\Program\uninstall.exe-q-splash uninstall
开始“%path%”
暂停

如果运行此代码,则会出现错误:

Windows cannot find 'C:\Program Files\Program\uninstall.exe -q -splash Uninstall'  
Make sure you typed the name correctly, and then try again.
若我移除开关,卸载过程将正常启动


那么,如何在批处理文件中使用此选项呢?

我不确定您遇到的每个程序是否都会在C:\program Files(将程序名放在此处)\directory中有一个uninstall.exe文件等待您。即使这样,您也可能必须从GUI控制它。但是,看看另一个堆栈溢出线程,我想感谢用户Bali C.和PA.提出了一个可能的解决方案,通过使用注册表项查找windows程序的卸载文件,使用批处理文件卸载文件。我将在下面重新粘贴PA的代码:

@echo off
for /f "tokens=*" %%a in ('reg query hklm\software\Microsoft\Windows\CurrentVersion\Uninstall\ ^| find /I "%*"') do (
  for /f "tokens=1,2,*" %%b in ('reg query "%%a" /v UninstallString ^| find /I "UninstallString"') do (
    if /i %%b==UninstallString (
      echo %%d
    )
  )
)
此代码将从注册表中找到特定程序的卸载文件,然后打印出运行卸载文件所需的命令。当您确定这些命令正确时,删除“echo”以仅运行这些命令。但是,即使这样,也可能需要使用程序的卸载GUI。我不认为这会是非常低效的。除了效率之外,您还想使用批处理文件吗


我希望这有帮助

作为旁白,不要使用
path
作为任意变量名选择。它在Windows(以及Unix派生系统)中具有特殊意义

您的主要问题是,您将开关包括在带引号的字符串中,然后将其作为一个整体视为可执行文件名。仅在文件名周围加引号,并将开关保留在外部:

SET command="C:\Program Files\Program\uninstall.exe" -q -splash Uninstall
START "" %command% 
(使用引号的唯一原因是路径名包含空格。)


另外,您根本不需要使用变量,但自从您使用变量后,我就使用了变量。

谢谢您的回复。我从你的评论中学到了太多东西。我很乐意以任何方式帮助你!