没有错误对话框的批处理文件

Batch file without error dialog

我需要创建一个批处理文件 运行 这个命令

start chrome

问题是我不确定机器上是否安装了 Google Chrome。我不能依赖注册表,因为我没有管理员权限。

如果我 运行 在未安装 Chrome 的机器上执行此命令,我会收到此错误对话框

(你看"chromex"。我用这个名字来模拟没有软件的情况。

有没有办法避免显示这个对话框?

下一个代码片段可能有所帮助:

@ECHO OFF >NUL
SETLOCAL enableextensions
SET "_chromePath="
If DEFINED programfiles(x86) (
  For /F "tokens=*" %%G in (
    'where /R "%programfiles(x86)%" chrome.exe  2^>NUL'
  ) do SET "_chromePath=%%G"
)
If NOT DEFINED _chromePath (
  For /F "tokens=*" %%G in (
    'where /R "%programfiles%" chrome.exe  2^>NUL'
  ) do SET "_chromePath=%%G"
)
If DEFINED _chromePath (
  echo start "" "%_chromePath%"
) else (
  echo chrome.exe not found
)

注意 start "" "%_chromePath%" echo 编辑仅用于调试目的。

资源(必读):

@echo 关闭

echo 输入1启动Chrome

set /p input=在此处输入:

if %input%==1 goto chrome

:chrome

回显开始chrome...

开始chrome.exe

暂停

对话框来自使用“开始”。直接执行文件以查看命令提示符的等价物。

'cat.exe' is not recognized as an internal or external command,
operable program or batch file.

通常打开网站,windows 将使用用户选择的浏览器。

Start "" www.microsoft.com
start "" "c:\windows\help\mmc\htm\mmc_1.htm"

I can't rely on the registry because I will not have admin permissions.

您作为用户具有对大部分注册表的读取权限,并且可以基于每个用户覆盖大多数设置和文件关联。