<bmacd5153@xxxxxx> wrote in message
news:3e8b52f6-c37a-4697-92cf-3112308c1f6a@xxxxxx
On Mar 17, 1:26 am, "Pegasus [MVP]" <n...@xxxxxx> wrote:
> You need to break your problem down into its invididual components in
> order
> to resolve it. The first question is, of course: Do expanded string values
> always get resolved properly, even when they contain environmental
> variables
> themselves? I recommend you do this:
> 1. Manually create a couple of variables in HKCU\Environment, e.g.
> vorpal1=%windir%
> vorpal2=%logonserver%
> 2. Insert the following commands into your logon batch file:
> echo Windir=%windir%
> echo Logonserver=%logonserver%
> echo Vorpal1=%vorpal1%
> echo Vorpal2=%vorpal2%
> pause
>
> This was the first step. If this step does not already answer your
> question
> then you should invoke your VB Script from the above batch file, just
> before
> the Pause command. If there is a discrepancy in the output you see then it
> may be necessary to examine your VB Script in greater detail.- Thanks,
The test is an interesting one
When run, the script will expand any variable reliably as long as the
environment variable to be expanded is defined in HKLM\System
\CurrentControlSet\Control\Session Manager\Environment.
All others are ignored.
This is the code that is used to retrieve them:
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
Machine & "\root\default:StdRegProv")
nRV = oReg.GetExpandedStringValue(hTree, sKeyPath, sValueName,
vValue)
I suspected the "Impersonate" section, but the results were the same
when I removed it. nRV is "0" after execution of the second line, so
it is finding the values in the registy, it is just not expanding the
contents UNLESS the variable is in system enviroment. Variables added
by the process, or variables in the User's default environment are not
expanded. I can find nothing that documents this, nor do I find
others complaining about it.
--Vorpal
==============
You can use the code below to extract any environmental variable, regardless
of the hive where it is stored.
Set wshShell = CreateObject("WScript.Shell")
For Each strEnv In Array("PROCESS", "SYSTEM", "USER", "VOLATILE")
WScript.Echo VbCrLf & VbCrLf & strEnv & "-Environment:" & VbCrLf
For Each str In wshShell.Environment(strEnv)
WScript.Echo wshShell.ExpandEnvironmentStrings(str)
Next
Next