繁体   English   中英

使用命令提示符,如何获取chrome exe的安装路径?

[英]Using command prompt , How can I get the path where chrome exe is installed?

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

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

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

我的批处理文件的内容是:我要在运行时获取突出显示的代码的位置,而不是将其硬编码到我的.bat文件中

(我把帮助这个获得管理员权限。)

@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

从注册表中获取Google Chrome的安装位置

"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%"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM