[英]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.