variable from registry (batch files)

2020-03-08 07:34发布

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_MACHINE\SOFTWARE\Maxis\The Sims]
"InstallPath"="C:\\Program Files\\Maxis\\The Sims"

now, i need this to be a variable in my bat file, like

set simsdir=%installpath%

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

Cheers

1条回答
兄弟一词,经得起流年.
2楼-- · 2020-03-08 08:02

Sounds like you need to call reg.exe

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_MACHINE\SOFTWARE\Maxis\The 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%

edit

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_MACHINE\SOFTWARE\Maxis\The 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%
查看更多
登录 后发表回答