Batch file - Discovered program path (variable) - Run program from discovered reg value (path)

让人想犯罪 __ 提交于 2019-12-02 04:50:55

问题


I'm trying to create a batch file that will discovered the location of a EXE in this case Steam, and runs that EXE with the discovered path from the registry. The reason I want to discover the install path via the registry is because this batch file is to run over multiple machines and the Steam install paths could be different.

The registry is the constant that holds these paths. Now I believe Steam stores it's install path at:

"HKEY_CURRENT_USER\Software\Valve\Steam\"
SteamExe = X:\Path\Steam.exe

So first I need to know how to grab this value and then I would like to know how to take that value and input it into a run command so Steam runs.

Could you help?


回答1:


@echo off

for /f "tokens=1,3" %%E in ('reg query "HKEY_CURRENT_USER\Software\Valve\Steam"') do (
    if %%E==SteamExe echo "%%F"
)

pause

reg query Get all keys and values for the registry path.

for /f Visit each line of the queried registry data and split the data so "Name" is stored in 'E' and "Data" is stored in 'F'. If 'E' equals "SteamExe" then echo 'F', which will display the steam executable path.

Command-line version:

@for /f "tokens=1,3" %E in ('reg query "HKEY_CURRENT_USER\Software\Valve\Steam"') do @if %E==SteamExe @echo "%F"



回答2:


I approached another way, this will work.

setlocal

regedit /e reg_exported.tmp "HKEY_CURRENT_USER\Software\Valve\Steam"
find "SteamExe" reg_exported.tmp | findstr "SteamExe" >> line_exported.tmp
set /p SteamPath= < line_exported.tmp
set SteamPath=%SteamPath:~11%

del reg_exported.tmp
del line_exported.tmp

start "Steam" %SteamPath%

endlocal


来源:https://stackoverflow.com/questions/12069300/batch-file-discovered-program-path-variable-run-program-from-discovered-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!