简体   繁体   English

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

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

I am writing a batch file and I need to start chrome exe using that batch file . 我正在编写一个批处理文件,我需要使用该批处理文件启动chrome exe。 So for that I need to get the path of the directory where chrome is installed . 因此,我需要获取chrome安装目录的路径。

Usually it is installed in " C:\\Program Files (x86)\\Google\\Chrome\\Application" but some users change the path while they install chrome. 通常将其安装在“ C:\\ Program Files(x86)\\ Google \\ Chrome \\ Application”中,但是某些用户在安装chrome时会更改路径。

I will like to get the path of that chrome exe on run time using command prompt and start it from there. 我想在运行时使用命令提示符获取该chrome exe的路径,然后从那里启动它。

The content of my batch file are : Where for the highlighted code I want to get on run time instead of hard coding it into my .bat file 我的批处理文件的内容是:我要在运行时获取突出显示的代码的位置,而不是将其硬编码到我的.bat文件中

(I took help of this to get admin rights.) (我把帮助这个获得管理员权限。)

@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

Get the installed location of Google Chrome from the registry 从注册表中获取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"

Example: 例:

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.

相关问题 如何在 windows 中使用命令提示符获取 chrome 版本 - How to get chrome version using command prompt in windows 使用Path解决方案后,我无法获得命令提示符以读取Javac命令。 (Windows 8.1 64位) - I can't get my Command Prompt to read javac commands after using the Path solution. (Windows 8.1 64bit) 为什么我不能从命令提示符运行这个 exe 文件? - why can't I run this exe file from the command prompt? 如何在系统路径中找到文件的位置,例如 get-command 或 where? - How can I find the location of a file in the system path, like get-command or where? 如何通过命令提示符启动exe并从命令提示符窗口获取文本 - How to launch an exe by command prompt and get text from command prompt window 如何使用C ++与命令提示符(CMD)进行通信? - How can I communicate with Command Prompt (CMD) using C++? 如何在命令提示符下运行.exe文件? - How to run a .exe file with command prompt? 我如何访问随anaconda提示安装的vim? - How can I access the vim installed with the anaconda prompt? 如何在Windows命令提示符下使用单个命令获取java版本? - How to get java version using single command in Windows command prompt? 如何将时间附加到此命令提示符date命令 - How can I append time to this command prompt date command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM