cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
honolua
Level 7

REGDB_STRING_EXPAND not working?

I'm having some trouble with getting the following code to expand the environment variable value returned in szValue. szValue contains "%windir%\system32\inetsrv". Should the following code not expand %windir% before it is returned into szValue?

szName = "InstallPath";
nSize = -1;
nType = REGDB_STRING_EXPAND;
nResult = RegDBGetKeyValueEx( szKey, "InstallPath", nType, szValue, nSize );


Edit:
The machine this is having issues on is a Windows 2008 Server machine. When I run some test code on my XP machine using the exact same code the variable is expanded just as expected.
Labels (1)
0 Kudos

(3) Replies
honolua
Level 7

No ideas what causes the expansion to fail on 2008 Server but work exactly as expected on XP?
0 Kudos
RobertDickau
Flexera Alumni

I don't have a Windows Server 2008 system at hand, but, if nothing else, does KB article Q101686 help?

(As an aside, RegDBGetKeyValueEx tells you what kind of data you just read, as opposed to the caller specifying what type of value it will read, so it shouldn't be necessary to set the type to REGDB_STRING_EXPAND beforehand.)
0 Kudos
honolua
Level 7

Many thanks Robert. The ExpandEnvironmentStrings() from KB article Q101686 has resolved the issue of the non-expanded string.
0 Kudos