Using environment variables in windows registry

1

I have a game that normally saves everything to the same folder. I want to have a separate save folder for each windows 7 account. The game's save path is stored in the windows registry. It doesn't seem to accept environment variables in the save path. Is it the game, a syntax error or are environment variables in the registry not resolved at runtime?

default

Save Path   REG_SZ   C:\Program Files (x86)\Diablo II\Save\

working with absolute path

Save Path   REG_EXPAND_SZ   C:\Users\account\Saved Games\Diablo II

not working with env variable

Save Path   REG_EXPAND_SZ   %USERPROFILE%\Saved Games\Diablo II

Note: According to a post I found on superuser REG_SZ should be changed to REG_EXPAND_SZ when using env variables. Absolute paths work either way.

Thanks!

nailertn

Posted 2013-10-11T14:54:51.833

Reputation: 11

In way way does it not "accept environment variables in the save path"? – martineau – 2013-10-11T16:22:01.110

@martineau When a save path is working the game displays saved games found there, otherwise it falls back on the default location. When I modify the registry value to %USERPROFILE%\Saved Games\Diablo II only saves from the default path are displayed. I don't know if it's the syntax, the registry or the game where it goes wrong. – nailertn – 2013-10-11T16:34:17.840

Your syntax is correct. The problem seems likely due to the fact that an application has to call a specific win32 API function, ExpandEnvironmentStrings, to get the values substituted.

– martineau – 2013-10-11T20:28:48.697

If the game is using HKLM\Diablo\foo\bar\Save Path, try setting HKCU\Diablo\foo\bae\Save Path. Some programs use the convention of looking there first. AFAIK, this is strictly a decision of the program (i.e., how it was designed), so some might do it while others do not. – Scott – 2013-10-12T03:45:55.953

No answers