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

前端 未结 2 808
梦谈多话
梦谈多话 2021-01-20 04:28

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

相关标签:
2条回答
  • 2021-01-20 04:56
    @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"
    
    0 讨论(0)
  • 2021-01-20 05:09

    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
    
    0 讨论(0)
提交回复
热议问题