Windows Vista Forums

REG_EXPAND_SZ only seems to expand some variables

  1. #1


    vorpal Guest

    REG_EXPAND_SZ only seems to expand some variables

    Reference:
    http://msdn.microsoft.com/en-us/libr...55(VS.85).aspx

    Test code:
    const HKEY_LOCAL_MACHINE = &H80000002
    Const HKCU=2147483649

    strComputer = "."
    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
    strComputer & "\root\default:StdRegProv")
    strKeyPath = "software\khpp\jbm"
    strValueName = "TestVal"
    Return = objReg.GetExpandedStringValue(HKCU,_
    strKeyPath,strValueName,strValue)
    If (Return = 0) And (Err.Number = 0) Then
    WScript.Echo "The Test Value is: " & strValue
    Else
    Wscript.Echo _
    "GetExpandedStringValue failed. Error = " & Err.Number
    End If

    I lifted this test code directly from the above, and it works.
    I pointed the GetExpandedStringValue to a different value as you can
    see.

    If I put "%windir% in TestVal, the output is "c:\windows"
    If I put %LOGONSERVER% in TestVal, the output is "%LOGONSERVER%

    Is there somewhere that documents which environment variables are
    expanded?
    Is there a way in vbScript to expand the others w/o resorting to
    the ExpandEnvironmentStrings method?
    I can live with ExpandEnvironmentStrings if I must, but I would like
    to understand more about why I must.

    Cheers,
    Vorpal


    :

      My System SpecsSystem Spec

  2. #2


    Pegasus [MVP] Guest

    Re: REG_EXPAND_SZ only seems to expand some variables


    "vorpal" <brumac@xxxxxx> wrote in message
    news:2219260c-8fff-41ad-8910-6abea179946e@xxxxxx

    > Reference:
    > http://msdn.microsoft.com/en-us/libr...55(VS.85).aspx
    >
    > Test code:
    > const HKEY_LOCAL_MACHINE = &H80000002
    > Const HKCU=2147483649
    >
    > strComputer = "."
    > Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
    > strComputer & "\root\default:StdRegProv")
    > strKeyPath = "software\khpp\jbm"
    > strValueName = "TestVal"
    > Return = objReg.GetExpandedStringValue(HKCU,_
    > strKeyPath,strValueName,strValue)
    > If (Return = 0) And (Err.Number = 0) Then
    > WScript.Echo "The Test Value is: " & strValue
    > Else
    > Wscript.Echo _
    > "GetExpandedStringValue failed. Error = " & Err.Number
    > End If
    >
    > I lifted this test code directly from the above, and it works.
    > I pointed the GetExpandedStringValue to a different value as you can
    > see.
    >
    > If I put "%windir% in TestVal, the output is "c:\windows"
    > If I put %LOGONSERVER% in TestVal, the output is "%LOGONSERVER%
    >
    > Is there somewhere that documents which environment variables are
    > expanded?
    > Is there a way in vbScript to expand the others w/o resorting to
    > the ExpandEnvironmentStrings method?
    > I can live with ExpandEnvironmentStrings if I must, but I would like
    > to understand more about why I must.
    >
    > Cheers,
    > Vorpal
    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.



      My System SpecsSystem Spec

  3. #3


    bmacd5153 Guest

    Re: REG_EXPAND_SZ only seems to expand some variables

    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

      My System SpecsSystem Spec

  4. #4


    Pegasus [MVP] Guest

    Re: REG_EXPAND_SZ only seems to expand some variables


    <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



      My System SpecsSystem Spec

  5. #5


    vorpal Guest

    Re: REG_EXPAND_SZ only seems to expand some variables

    On Mar 18, 10:12*am, "Pegasus [MVP]" <n...@xxxxxx> wrote:

    > <bmacd5...@xxxxxx> wrote in message
    >
    > ==============
    >
    > 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
    If I'm not mistaken, though the code above only works on the machine
    on which the script is running.
    WMI works on remote machines, and it is for that reason I wanted to
    use it.
    --Vorpal

    --Vorpal

      My System SpecsSystem Spec

REG_EXPAND_SZ only seems to expand some variables

Similar Threads
Thread Forum
Expand a vhd
No doubt this has been asked a thousand times. Easy way to increase the size of a vhd? I seem to have underestimated how quickly I would use up the...
Virtual PC
How to Expand Partition?
Very sorry if this is a dup posting. I tried posting about 45 min ago and my post hasn't shown up yet. Thought I did something wrong the first time....
Virtual Server
math with "GB/MB/KB" in variables fails, without variables works?
I'm making a script to calculate time for a file to download, I want to be able to input things like "10GB" and "5GB" and "3.3KB" in the following...
PowerShell
Expand Explorer
Whenever I open Windows Explorer, is there a way I can have it open expanded rather than just showing Desktop, Documents, etc. I want the C: drive...
Vista General
Expand Sub Directories
In XP you could click on a directory in explorer and it would instantly expand the sub directories. Is there a setting in Vista that will cause...
Vista General
Sundeep Raina:) variables being handled in Workflow and How to declare New Variables
Hi:) and Microsoft People :) Please Can Some one Tell me abt wheather variables being handled in Workflow and How to declare New Variables
WinFX General
Sundeep Raina(Iopsis): Is variables being handled in Workflow and How to declare New Variables
Hi:) and Microsoft People :) Please Can Some one Tell me abt wheather variables being handled in Workflow and How to declare New Variables..
Avalon