Page 1 of 1 1
Topic Options
#180757 - 2007-09-20 01:17 PM environment variable
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Hello All,

I must be missing something simple. I have a Windows XP Pro SP 2 system using kixtart vs 4.53. I have read ProfileImagePath from the registry where the value starts with "%SystemDrive%." Every time I try to use this variable, kixtart isn't substituting "C:" for "%SystemDrive%." For example, I have the value from ProfileImagePath in the variable, $strPath and do the following:

 Code:
$strFilename = Dir($strPath + "\*.*")


$strFilename is always blank. I even tried to pull the environment variable out of the front of the variable and put it in its own variable to try and force the evaluation, but that did not work as follows:

 Code:
$strVariable = Substr($strPath,1,Instr(Substr($strPath,2),"%")+1)
? "strVariable is: " + $strVariable


All I get out is %SystemDrive%. What am I doing wrong?

Thanks!

Brad V

Top
#180758 - 2007-09-20 01:49 PM Re: environment variable [Re: BradV]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
How about:

 Quote:

EXPANDENVIRONMENTVARS
Action
Expands any environment variables inside a string to the corresponding plain text value.

Syntax
EXPANDENVIRONMENTVARS ("string")

Parameter
String
The string you want to expand.
Returns

The expanded string.

Example
$Value = ReadValue("HKLM\System\CurrentControlset\Control\Windows", "SystemDirectory" )

? ExpandEnvironmentVars( $Value )


It's in the manual ;\)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#180759 - 2007-09-20 03:22 PM Re: environment variable [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Just to clarify Mart's reference, if you build a string like this:
$sTmp = "%WINDIR%" + " is the windows root folder." + @CRLF
Kix will automatically reference the contents of the %WINDIR% variable.

When you read the value from the registry, and the registry value type is REG_SZ, it will return the environment variable name, just as it appears in the data in the registry. Since the env-var is embedded in the string, you need to use the ExpandEnvironmentVars(). Often, we use something like:
 Code:
$Value = ExpandEnvironmentVars(ReadValue($Key))


Keep in mind that some registry values are the type REG_EXPAND_SZ. These can hold an environment variable, but the act of reading this value performs the required environment variable replacement automatically. Using the medhod above provides no advantage, but doesn't hurt either. I point this out because sometimes you read a value and get what you expect, and other times you get a raw environment var - the difference is the value data type.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#180764 - 2007-09-20 08:30 PM Re: environment variable [Re: Glenn Barnas]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Duh - I told you I was overlooking something simple! \:\)

Thanks!

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 756 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.052 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org