来自注册表的变量(批处理文件) [英] variable from registry (batch files)
问题描述
我正在为旧游戏 sims 1 制作一个小模组,我想我制作了一个简单的批处理文件来安装它,只是为了花哨.无论如何,在注册表中你可以找到安装路径
I am making a little mod for the old game sims 1, and i thought i make a simple batch file for installing it, just to be fancy. anyway, in the registry you can find the installpath
[HKEY_LOCAL_MACHINESOFTWAREMaxisThe Sims]
"InstallPath"="C:\Program Files\Maxis\The Sims"
现在,我需要将它作为我的 bat 文件中的变量,例如
now, i need this to be a variable in my bat file, like
set simsdir=%installpath%
我该怎么做?我用谷歌搜索了它,但对我来说没有任何意义,这就是我在这里问的原因:p
how do i do this? ive googled it but it made no sense what so ever to me so, thats why i am asking here :p
干杯
推荐答案
听起来你需要调用 reg.exe
771240 上接受的答案看起来有你需要的语法.我没有对此进行测试,但它应该看起来像
The accepted answer on 771240 looks to have the syntax you'll need. I've not tested this, but it should look something like
Set Reg.Key=HKEY_LOCAL_MACHINESOFTWAREMaxisThe Sims
Set Reg.Val=InstallPath
For /F "Tokens=2*" %%A In (
'Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"' )
Do Call Set simsdir=%%B
echo %simsdir%
编辑
也许可以在一条线上尝试使用 for all,这是我可以让它工作的唯一方法.不过,我对 'ol 批处理文件有点生疏了
Maybe try it with the for all on the one line, that's the only way I could get it to work. I'm a bit rusty on the 'ol batch files though
Set Reg.Key=HKEY_LOCAL_MACHINESOFTWAREMaxisThe Sims
Set Reg.Val=InstallPath
For /F "Tokens=2*" %%A In ('Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"' ) Do Call Set simsdir=%%B
echo %simsdir%
这篇关于来自注册表的变量(批处理文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!