Page 1 of 1 1
Topic Options
#124470 - 2004-08-05 12:31 PM READPROFILESTRING snags
mcintyrj Offline
Just in Town

Registered: 2004-06-24
Posts: 2
Loc: UK
I am having a couple of problems with READPROFILESTRING: probably just not understanding how it is supposed to work...

Code:
 Break Off
; This script adds the following lines to the Appsrv.ini file in the users profile
; SSOnUserSetting=On
; EnableSSOnThruICAFile=On

$appsrvini = "%USERPROFILE%\Application Data\ICAClient\appsrv.ini"

;Does File Exist?

IF EXIST ($appsrvini) = 1

;Does section [WFCLIENT] Exist?
$nul=READPROFILESTRING ($appsrvini, "WFClient", "")
IF @ERROR = 0 ;if Section exists
;Add/modify lines to [WFCLIENT] section
$nul=WriteProfileString($appsrvini,"WFClient","SSOnUserSetting","On")
$nul=WriteProfileString($appsrvini,"WFClient","EnableSSOnThruICAFile","On")
ELSE
? @ERROR
;WFClient section missing from appsrv.ini file.
?"WFClient section missing from appsrv.ini file."
ENDIF

ELSE
;appsrv.ini does not exist in the users profile
?"appsrv.ini does not exist in the users profile"
ENDIF


?"finished"




get $nul



I test the script and it works fine.
I remove the [WFclient] section to test the result and the READPROFILESTRING still returns a '0'. When I echo $nul at this point I find the string contains:

SSOnUserSetting
EnableSSOnThruICAFile

This explains why it is returning a '0' - but where on earth is it picking these entries up from. The section does not exist in the ini file.

any thoughts welcome...

Top
#124471 - 2004-08-05 12:42 PM Re: READPROFILESTRING snags
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it actually should return nothing...
remembering the methods ini-codes work, they don't even set @error, iirc.

if you only removed the section header, then it seems to give you orphan items (which have no section defined).

the 0 is still rather odd.
it should return nothing.
_________________________
!

download KiXnet

Top
#124472 - 2004-08-05 01:17 PM Re: READPROFILESTRING snags
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
What he said.

You will always get a success status (so long as the file exists).

To check for the existance of a section, use "ReadProfileString" with a null section name to get all the sections, then check if your section is present.

Something like this should do:
Code:
$NL=Chr(10)
$sSection="WFClient"
If InStr($NL+ReadProfileString("MyIniFile.ini","",""),$NL+$sSection+$NL)
"Section '"+$sSection+"' exists in ini file" ?
Else
"Section '"+$sSection+"' does not exist in ini file" ?
EndIf



Top
#124473 - 2004-08-05 02:30 PM Re: READPROFILESTRING snags
Anonymous
Unregistered


Thanks people - Richard's script works a treat
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 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.05 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

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