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?

Thanks in advance.

Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Dave

Dave
Mon Aug 14 20:49:07 CDT 2006

Set WshShell = CreateObject("WScript.Shell")
WScript.Echo WshShell.ExpandEnvironmentStrings("%systemroot%")

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Scott" 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?
|
| Thanks in advance.
|
|



Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Scott

Scott
Mon Aug 14 22:03:02 CDT 2006

Well, thank you for trying, but sorry to say your answer is doubly wrong:

(1) I want to read a REG_EXPAND_SZ value from the Registry, not get the
value of an Environment variable;
(2) I said I want the variable to NOT expand to its value; the solution you
suggest DOES the expansion.

Anyone else???



"Dave Patrick" wrote:

> Set WshShell = CreateObject("WScript.Shell")
> WScript.Echo WshShell.ExpandEnvironmentStrings("%systemroot%")
>
> --
>
> Regards,
>
> Dave Patrick ....Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
>
> "Scott" 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?
> |
> | Thanks in advance.
> |
> |
>
>
>

Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Dave

Dave
Mon Aug 14 22:21:29 CDT 2006

Sorry, apparently my crystal ball must have malfunctioned.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Scott" <Scott@discussions.microsoft.com> wrote in message
news:269F3549-99D2-4696-818A-D593D1D729D9@microsoft.com...
| Well, thank you for trying, but sorry to say your answer is doubly wrong:
|
| (1) I want to read a REG_EXPAND_SZ value from the Registry, not get the
| value of an Environment variable;
| (2) I said I want the variable to NOT expand to its value; the solution
you
| suggest DOES the expansion.
|
| Anyone else???



Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Scott

Scott
Mon Aug 14 22:34:02 CDT 2006

:-)


"Dave Patrick" wrote:

> Sorry, apparently my crystal ball must have malfunctioned.
>
> --
>
> Regards,
>
> Dave Patrick ....Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
>
> "Scott" <Scott@discussions.microsoft.com> wrote in message
> news:269F3549-99D2-4696-818A-D593D1D729D9@microsoft.com...
> | Well, thank you for trying, but sorry to say your answer is doubly wrong:
> |
> | (1) I want to read a REG_EXPAND_SZ value from the Registry, not get the
> | value of an Environment variable;
> | (2) I said I want the variable to NOT expand to its value; the solution
> you
> | suggest DOES the expansion.
> |
> | Anyone else???
>
>
>

Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Justin

Justin
Tue Aug 15 09:52:16 CDT 2006

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)


--
Justin Piper
Bizco Technologies
http://www.bizco.com/

Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Alexander

Alexander
Tue Aug 15 11:27:52 CDT 2006

Scott schrieb:

> 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?

simply regread it. WshShell.RegRead doesn't seem to expand it:

set ws = createobject("Wscript.shell")
const k = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg\PathName"
msgbox ws.regread(k)

MfG,
Alex

Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Scott

Scott
Wed Aug 16 13:31:02 CDT 2006

Yes, indeed, this is the answer.

I could swear I tried this very thing that day, and it *was* doing the
substitution. Today this works for me as you say it should and as I want.
Computers don't change their behavior from day to day, do they? ;-) It must
have been me (and whatever I really did is now lost to my memory). :-(

Still (see my reply to another person in this thread) I had other problems
that day too. Maybe my computer was funky that day.

Thanks for your help!

--Scott

"Alexander Mueller" wrote:

> Scott schrieb:
>
> > 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?
>
> simply regread it. WshShell.RegRead doesn't seem to expand it:
>
> set ws = createobject("Wscript.shell")
> const k = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg\PathName"
> msgbox ws.regread(k)
>
> MfG,
> Alex
>

Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Scott

Scott
Wed Aug 16 14:05:02 CDT 2006

Interesting proposal. I'd bet this would work.

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.)

(Acutally I made the mistake of doing the above Environment change to the
USER and SYSTEM environments too, and made my computer unbootable!!! That
was a scary 1/2 hour getting my maching working again!)

Anyway: thanks for your proposed solution.

--Scott


"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)
>
>
> --
> Justin Piper
> Bizco Technologies
> http://www.bizco.com/
>

Re: How to read Registry STRING_EXPAND_SZ WITHOUT EXPANDING? by Justin

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/