#125244 - 2004-08-18 04:09 PM
Read Windows Variables From INI
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
When I read entries from an INI file such as %UserProfile% I seem to be having trouble getting those to function inside the code.. such as
Code:
$Test = ReadProfileString("C:\file.ini","Section1","WinVar") Where C:\file.ini is [SECTION1] WinVar=%USERPROFILE%
But if I say Code:
?"Var= "%USERPROFILE% it will work...
Is there any way to read these dynamic type things from ini file? Thanks in advance for the help.
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#125245 - 2004-08-18 04:13 PM
Re: Read Windows Variables From INI
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You need to expand the variable.
One simple method is:
Code:
$Test = ReadProfileString("C:\file.ini","Section1","WinVar")
$=Execute('$$Test="$Test"')
"Variable is now "+$Test+@CRLF
Note, this example requires that NoVarsInStrings is *not* ON.
|
|
Top
|
|
|
|
#125246 - 2004-08-18 04:34 PM
Re: Read Windows Variables From INI
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
What is NoVarsInStrings ? I dont believe I have seen that one before.. and a search of the CHM file doesnt turn anything up either.
Thanks for the help
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#125247 - 2004-08-18 04:40 PM
Re: Read Windows Variables From INI
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Ahh.. got it
Code:
$ItemPath = ReadProfileString("$INIPath",$Section,"ItemPath") $Silent = Execute('$$ItemPath = "$ItemPath"')
Where the ini entry looks like.. ItemPath=%USERPROFILE%\Start Menu\Test.exe
Thanks for your help.. I dont think I ever knew about execute() either.. always something new to learn.
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#125249 - 2004-08-18 04:53 PM
Re: Read Windows Variables From INI
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Look under "SetOption()" for NoVarsInStrings and similar.
For good coding practice you would normally set NoVarsInStrings and Explicit ON.
Another way to expand the variable is to use ExpandEnvironmentVars().
In your case you could shorten the code to: Code:
$ItemPath=ExpandEnvironmentVars(ReadProfileString("$INIPath",$Section,"ItemPath"))
So, why did I show you the Execute() method?
Well, Execute() is very useful for many tricks like this - variable variable names are another one, so it's worth learning.
Another benefit of using Execute() is that you can include KiXtart macros and variables in the ini file as well as environment variables. In fact your ini file could contain mini KiXtart scripts!
|
|
Top
|
|
|
|
#125250 - 2004-08-18 05:45 PM
Re: Read Windows Variables From INI
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Quote:
So, why did I show you the Execute() method?
Well, Execute() is very useful for many tricks like this - variable variable names are another one, so it's worth learning.
Another benefit of using Execute() is that you can include KiXtart macros and variables in the ini file as well as environment variables. In fact your ini file could contain mini KiXtart scripts!
yeah, execute is a nice one to learn. I used it for a program that does just what richard said... my ini file contained miny kix scripts and kix commands.
also, it plays a huge role in kixforms 
Bryce
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 699 anonymous users online.
|
|
|