Board index » cppbuilder » Cannot write to file problem.

Cannot write to file problem.


2004-11-09 03:15:00 AM
cppbuilder72
Hi,
My application is a multi-user application that retrieves
wind data from the internet. It works fine when run in an administrator
session, however under a user session, config files cannot be saved.
TStringList *Config = new TStringList();
Config->LoadFromFile(...);
...
Config->SaveToFile(); Fails with ERROR_ACCESS_DENIED
delete Config;
These config files are stored in:
C:\Documents and Settings\All Users\Application Data\ApplicationName\
I thought that files written in that directory could be written by
any user, but apparently not... Are they still owned by the
administrator who created them?
What can I do to enable writing to these files?
I'm close to getting nuts ... please help,
David
 
 

Re:Cannot write to file problem.

"David Monbaron" < XXXX@XXXXX.COM >wrote in message
Quote
My application is a multi-user application that retrieves
wind data from the internet. It works fine when run in an
administrator session, however under a user session,
config files cannot be saved.
Sounds like your user account does not have permissions to the files. That
is a configuration issue in the OS, not in your code.
Quote
These config files are stored in:
C:\Documents and Settings\All Users\Application Data\ApplicationName\

I thought that files written in that directory could be written by
any user, but apparently not... Are they still owned by the
administrator who created them?
They can be, yes.
Have you considered using the following folder instead?
C:\Documents and Settings\<UserName>\Application Data\ApplicationName\
Why is your admin account making files for other accounts? Why are they not
making their own files?
Quote
What can I do to enable writing to these files?
Adjust your user account permissions.
Gambit
 

Re:Cannot write to file problem.

Remy Lebeau (TeamB) wrote:
Hey Remy,
Thanks for your answer,
Quote
"David Monbaron" < XXXX@XXXXX.COM >wrote in message
news:418fc5bd$ XXXX@XXXXX.COM ...


>My application is a multi-user application that retrieves
>wind data from the internet. It works fine when run in an
>administrator session, however under a user session,
>config files cannot be saved.


Sounds like your user account does not have permissions to the files. That
is a configuration issue in the OS, not in your code.
I checked and I'm running Windows XP Pro and I only get the choice
between System Admin and Limited. I get this Under Control Panel>User
Accounts. Anyway to change permissions?
Quote


>These config files are stored in:
>C:\Documents and Settings\All Users\Application Data\ApplicationName\
>
>I thought that files written in that directory could be written by
>any user, but apparently not... Are they still owned by the
>administrator who created them?


They can be, yes.

Have you considered using the following folder instead?

C:\Documents and Settings\<UserName>\Application Data\ApplicationName\
Yes, Remy I have considered this and actually have done it for another
application but for this one it's not suitable as any user logged in on
the machine should have access to the wind data retrieved by another
user. Basically I have to have a shared file where any user can read and
write to. How can I do that? (SetFileSecurity?) If you have an example
that would be great...
Quote

Why is your admin account making files for other accounts? Why are they not
making their own files?

see above.

>What can I do to enable writing to these files?


Adjust your user account permissions.


Gambit


 

{smallsort}

Re:Cannot write to file problem.

Dear Remy,
I found this answer to my problem:
?CSIDL_COMMON_APPDATA.
This folder should be used for application data that is not user specific.
For example, an application may store a spell check dictionary, a database
of clip-art or a log file in the CSIDL_COMMON_APPDATA folder. This
information will not roam and is available to anyone using the computer. By
default, this location is read-only for normal (non-admin, non-power) Users.
If an application requires normal Users to have write access to an
application specific subdirectory of CSIDL_COMMON_APPDATA, then the
application must explicitly modify the security on that sub-directory during
application setup...
My QUESTION is HOW DO I MODIFY THE SECURITY ACCESS TO MY
CSIDL_COMMON_APPDATA SUBDIRECTORY DIRECTORY?
Thanks !
Remy Lebeau (TeamB) wrote:
Quote
"David Monbaron" < XXXX@XXXXX.COM >wrote in message
news:418fc5bd$ XXXX@XXXXX.COM ...


>My application is a multi-user application that retrieves
>wind data from the internet. It works fine when run in an
>administrator session, however under a user session,
>config files cannot be saved.


Sounds like your user account does not have permissions to the files. That
is a configuration issue in the OS, not in your code.


>These config files are stored in:
>C:\Documents and Settings\All Users\Application Data\ApplicationName\
>
>I thought that files written in that directory could be written by
>any user, but apparently not... Are they still owned by the
>administrator who created them?


They can be, yes.

Have you considered using the following folder instead?

C:\Documents and Settings\<UserName>\Application Data\ApplicationName\

Why is your admin account making files for other accounts? Why are they not
making their own files?


>What can I do to enable writing to these files?


Adjust your user account permissions.


Gambit


 

Re:Cannot write to file problem.

"David Monbaron" < XXXX@XXXXX.COM >wrote in message
Quote
My QUESTION is HOW DO I MODIFY THE SECURITY
ACCESS TO MY CSIDL_COMMON_APPDATA
SUBDIRECTORY DIRECTORY?
Please do not shout.
Look at SetFileSecurity() and related functions.
Gambit
 

Re:Cannot write to file problem.

Remy Lebeau (TeamB) wrote:
Quote
"David Monbaron" < XXXX@XXXXX.COM >wrote in message
news:4190b61d$ XXXX@XXXXX.COM ...


>My QUESTION is HOW DO I MODIFY THE SECURITY
>ACCESS TO MY CSIDL_COMMON_APPDATA
>SUBDIRECTORY DIRECTORY?


Please do not shout.

Look at SetFileSecurity() and related functions.


Gambit


Hey sorry,
didn't mean to insult you or whatever, it was just to get
the message clearer. Anyway you helped me to get to the right
place. I will have a look at SetFileSecurity but it already
looks tricky...
 

Re:Cannot write to file problem.

David Monbaron wrote:
Quote
Remy Lebeau (TeamB) wrote:

>"David Monbaron" < XXXX@XXXXX.COM >wrote in message
>news:4190b61d$ XXXX@XXXXX.COM ...
>
>
>>My QUESTION is HOW DO I MODIFY THE SECURITY
>>ACCESS TO MY CSIDL_COMMON_APPDATA
>>SUBDIRECTORY DIRECTORY?
>
>
>
>Please do not shout.
>
>Look at SetFileSecurity() and related functions.
>
>
>Gambit
>
>
Hey sorry,

didn't mean to insult you or whatever, it was just to get
the message clearer. Anyway you helped me to get to the right
place. I will have a look at SetFileSecurity but it already
looks tricky...
BTW I found a good component set that handles WindowsNT security
for you. It's called NTSet and can be found at
www.sam-solutions.net/products/description.php
Dave