Page 1 of 1 1
Topic Options
#198583 - 2010-05-11 11:43 AM WriteProfileString with write empty values
AvAxx Offline
Just in Town

Registered: 2006-11-06
Posts: 3
Recently I was looking for a way to write to an INI file key with no value. I did not find any posted solutions. And so I tried it myself. Comments are welcome

 Code:
WriteEmptyProfileString("%TEMP%\WriteEmptyProfileString.ini","TestSection","TestKey")

function WriteEmptyProfileString($ini,$section,$key)
  $error=0
  $=writeprofilestring($ini,$section,$key,@CRLF+$key+"=")
  if @error
    $error=@error
  else
    $=writeprofilestring($ini,$section,$key)
    if @error
      $error=$error+@error*1000
    endif
  endif
  $writeemptyprofilestring=$error
endfunction

Top
#198585 - 2010-05-11 02:41 PM Re: WriteProfileString with write empty values [Re: AvAxx]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It's not normally needed as a non-existent key is the same as a key with no value in strict INI terms.

However some software does break the "INI standard" and behave differently.

Another alternative is to write quotes as the value - a well behave application should strip them off and treat the value as empty:
 Code:
$=WriteProfileString('.\test.ini','Section','Key','""')

Top
#198591 - 2010-05-12 08:42 AM Re: WriteProfileString with write empty values [Re: AvAxx]
AvAxx Offline
Just in Town

Registered: 2006-11-06
Posts: 3
Yes, it is against logic. INI file for which I have addressed this issue contains the keys Username and Password. These keys have to be defined with value or no value.

  • without value - when you start the login window appears with empty fields username and password

  • values - if both keys are defined with a value program tries to apply directly

  • keys do not exist - the program automatically uses the login name as "admin" / password "admin" and tries to apply directly


[When username and password are invalid program throws an error window. After confirmation appear pre-filled logon window]

Because the user can set the default username and password through the GUI (the password is stored in plain text). And so was the auditing script that removes the password, but leave the key in the INI file.

Top
#198608 - 2010-05-13 10:54 PM Re: WriteProfileString with write empty values [Re: AvAxx]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Hi and welcome AvAxx!

Richard is quite right. Still, it sounds quite scary to have an ini within user-context available with username and passwords (?).
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#198618 - 2010-05-14 09:37 AM Re: WriteProfileString with write empty values [Re: Björn]
AvAxx Offline
Just in Town

Registered: 2006-11-06
Posts: 3
I fully agree - safety first, but the situation is more complex.

In the company recently conducted an information system upgrade Infor ERP Visual (formerly Lilly Software)
It is of course a client-server system (but not a thin client!)

Because it is the U.S. product must be localized for our country and it takes a lot of time (translation, national forms, tax laws, ... , testing)
It will sound strange, but the new product upgrades is already old in comparison with the current U.S. version - the difference is about 4-5 years!
Old and 'new' version uses a large number of INI files that the user must have full access. (%programfiles%\visual601\*.ini and %programfiles%\visual631\*.ini) btw. INI files are not interchangeable between versions.
Both versions are currently installed at stations to validate the functionality - the old version will be removed approx 1 year.
The IS client allows redirect path to the INI files, but these settings are common to both versions ... so problem

Because the user has full access to INI files and the GUI allows the pre-filling user name and password I was looking for a way to remove the password if the user fills it.

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 977 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.085 seconds in which 0.054 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