【问题标题】:Using command prompt , How can I get the path where chrome exe is installed?使用命令提示符,如何获取安装 chrome exe 的路径?
【发布时间】:2014-10-09 13:35:54
【问题描述】:

我正在编写一个批处理文件,我需要使用该批处理文件启动 chrome exe。所以为此我需要获取安装 chrome 的目录的路径。

通常安装在“C:\Program Files (x86)\Google\Chrome\Application”,但有些用户在安装 chrome 时会更改路径。

我想在运行时使用命令提示符获取该 chrome exe 的路径并从那里启动它。

我的批处理文件的内容是:我想在运行时将突出显示的代码放在哪里,而不是将其硬编码到我的 .bat 文件中

(我在this 的帮助下获得了管理员权限。)

@echo 
:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B
:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:----------------------https://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file----------------
echo Closing all instances of chrome.....
taskkill /f /im chrome.exe
echo All instances of chrome closed. Now going to chrome exe location 

cd **C:\Program Files (x86)\Google\Chrome\Application**
echo Reached to chrome exe location. Ready to start new chrome with web security off.
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

【问题讨论】:

    标签: windows google-chrome batch-file google-chrome-extension cmd


    【解决方案1】:

    从注册表中获取谷歌浏览器的安装位置

    "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command"
    "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet\Google Chrome\shell\open\command"
    

    例子:

    set "Command="
    for /f "tokens=2,*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command" /ve 2^>nul') do set "Command=%%~B"
    if not defined Command for /f "tokens=2,*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet\Google Chrome\shell\open\command" /ve 2^>nul') do set "Command=%%~B"
    if not defined Command echo Google Chrome was not found.
    if defined Command start "Browser" "%Command%"
    

    【讨论】:

    • 它在我的机器上工作正常,但在其他机器上却不行,因为其他机器上的 reg 值不同。我不知道原因。但这对我帮助很大。我需要问你一件事。我确定答案是否定的,但要求确认。我们可以在不同的机器上有不同的注册条目吗?
    • 根据用户安装浏览器的方式,它也可能位于 HKEY_CURRENT_USER 树下。见How to Register an Internet Browser or Email Client With the Windows Start Menu
    猜你喜欢
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 2014-01-02
    • 2019-05-28
    相关资源
    最近更新 更多