Justin
Wed Aug 16 15:36:45 CDT 2006
On Wed, 16 Aug 2006 14:05:02 -0500, Scott
<Scott@discussions.microsoft.com> wrote:
> "Justin Piper" wrote:
>
>> On Mon, 14 Aug 2006 20:34:01 -0500, Scott
>> <Scott@discussions.microsoft.com> wrote:
>>
>> > How can I read a STRING_EXPAND_SZ value from the Registry and get the
>> > %SystemRoot% (or any other possible substitute string for that matter)
>> > verbatim, without being substituted?
>>
>> There's surely a better way than this, but unsetting all the process
>> environment variables works:
>>
>> Option Explicit
>>
>> Const HKLM = "HKEY_LOCAL_MACHINE"
>> Const Key = "SOFTWARE\Microsoft\Windows
>> NT\CurrentVersion\WinLogon"
>> Const Value = "UIHost"
>>
>> Dim sh, env, var
>> Set sh = CreateObject("WScript.Shell")
>> Set env = sh.Environment("Process")
>> For Each var In env
>> var = Trim(Left(var, InStr(var, "=")-1))
>> If Len(var) > 0 Then env.Remove var
>> Next
>>
>> WScript.Echo sh.RegRead(HKLM & "\" & Key & "\" & Value)
>
> Curiously, I tried a variant of this the other day and it did not work
> for me. I did:
>
> Set WshProcessEnv = WshShell.Environment("PROCESS")
> WshProcessEnv("SystemRoot") = ""
>
> Yes, that is different than your use of the Remove method. Still,
> when I read the Registry that day after running the above, the
> susbtitution upon registry read continued to happen. (However as an
> aside, by that time in my experimenting I had switched from WshShell
> RegRead to WMI's winmgmts GetStringValue.)
I started from WMI, since I recalled that StdRegProv class had methods
for both string and expanded string data. The documentation for
GetExpandedStringValue suggests that this /should/ work, but I observed
the same behavior you report. Perhaps StdRegProv runs in a different
process.
Once I changed it to use RegRead it worked, so it never even occurred to
me to try it without clearing the environment until I saw Alex's
solution.
--
Justin Piper
Bizco Technologies
http://www.bizco.com/