批处理文件-发现的程序路径(变量)-从发现的reg值(路径)运行程序 [英] Batch file - Discovered program path (variable) - Run program from discovered reg value (path)

查看:192
本文介绍了批处理文件-发现的程序路径(变量)-从发现的reg值(路径)运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个批处理文件,在本例中为Steam,它将发现EXE的位置,并使用从注册表中找到的路径运行该EXE.我想通过注册表发现安装路径的原因是因为此批处理文件要在多台计算机上运行,​​并且Steam的安装路径可能不同.

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.

注册表是保存这些路径的常量.现在我相信Steam将其安装路径存储在:

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

所以首先我需要知道如何获取该值,然后我想知道如何获取该值并将其输入到运行命令中,以便Steam运行.

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.

你能帮忙吗?

推荐答案

@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获取注册表路径的所有键和值.

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

for /f访问查询的注册表数据的每一行并拆分数据,以便将名称"存储在"E"中,将数据"存储在"F"中. 如果"E"等于"SteamExe",则回显"F",这将显示Steam可执行文件路径.

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.

命令行版本:

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

这篇关于批处理文件-发现的程序路径(变量)-从发现的reg值(路径)运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆