Groups > Borland > Delphi upgrade > Re: File access denied




File access denied

File access denied
24 Mar 2008 15:33:20 -0700
Hello,

One of my applications needs to write some txt file, using assignfile, rewrite
and writeln functions. Everything worked fine in D6, but now we have upgraded to
Rad Studio 2007 and the users running Windows Vista with Account Control
switched on gets a 'File access denied' when the program tries to manipulated
the files. If the Account control is turned off, everything works fine.

Files are being writed in my application folder, inside Program files. Is there
a way to avoid this error without force the user to turn off Acount control ?
I'm wondering why the executable compiled with D6 does not have this problem.

Thanks
Post Reply
Re: File access denied
Mon, 24 Mar 2008 15:41:13 -070
"viana" <v@v.com> wrote in message
news:47e82c30$1@newsgroups.borland.com...

> Files are being writed in my application folder, inside Program files.

That is your mistake.  That folder is read-only, and has been since XP. 
That has nothing to do with the version of Delphi you are using.

> Is there a way to avoid this error without force the user to turn off
> Acount control ?

You should be write your files to the correct folder in the first place. 
Use SHGetSpecialFolderLocation() or similar function to retreive the user's 
CSIDL_DOCUMENTS folder, if the files are meant for the user to interact 
with.  Or to the CSIDL_APPDATA, CSIDL_LOCAL_APPDATA, or CSIDL_COMMON_APPDATA 
folder instead, depending on whether your files need to roam per-user or be 
shared amngst multiple users.  In the case of APPDATA, that folder is 
read-only itself, so you need to create your own read/write subfolder 
underneath it for your application, ie: %APPDATA%\MyName\MyApp\MyAppVersion.

Refer to MSDN for more details about CSIDL_... folders.  The requirement to 
use APPDATA folders is covered in several different places of MSDN.


Gambit 

Post Reply
Re: File access denied
24 Mar 2008 16:20:38 -0700
>> Files are being writed in my application folder, inside >Program
files.

>That is your mistake.  That folder is read-only, and has been >since XP.

>That has nothing to do with the version of Delphi you are >using.

thank you for your reply. but the weird thing is we've been using this
application for one year with no problems. these 'file access denied' are
reported by the users only now, when we upgraded to rad studio 2007, and only
with vista users, with account control enabled. that's why i think the problem
has to do somehow with d2007.

anyway, i'll follow your advice, and create a folder on appdata.

thanks in advance.

viana

Post Reply
Re: File access denied
Mon, 24 Mar 2008 16:25:24 -070
"viana" <v@v.com> wrote in message
news:47e83746$1@newsgroups.borland.com...

> thank you for your reply. but the weird thing is we've been using this
> application for one year with no problems. these 'file access denied'
> are reported by the users only now, when we upgraded to rad studio
> 2007, and only with vista users, with account control enabled. that's
> why i think the problem has to do somehow with d2007.

Again, it has nothing to do with the version of Delphi being used.  This is 
an OS permissions issue, as evident by the fact that everything works when 
UAC is disabled.  What is likely happening is that you are running your D6 
app as an elevated admin, but are not running the D2007 app as such.


Gambit 

Post Reply
Re: File access denied
24 Mar 2008 17:07:05 -0700
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"viana" <v@v.com> wrote in message
news:47e83746$1@newsgroups.borland.com...
>
>> thank you for your reply. but the weird thing is we've been using this
>> application for one year with no problems. these 'file access denied'
>> are reported by the users only now, when we upgraded to rad studio
>> 2007, and only with vista users, with account control enabled. that's
>> why i think the problem has to do somehow with d2007.
>
>Again, it has nothing to do with the version of Delphi being used.  This is

>an OS permissions issue, as evident by the fact that everything works when 
>UAC is disabled.  What is likely happening is that you are running your D6 
>app as an elevated admin, but are not running the D2007 app as such.

Ok, it may be a coincidence then.

Problem is i keep some files hide in Windows or System32 directory, usually
files with registration information. This is usefull to help avoid cracking, as
if i put these files on a appdata, it's much easier for a cracker to find it.
And the strange thing is that when i used D6, i always kept the files on Windows
or System32 directory with no problems at all. Only after upgraded a lot of
users have this 'File access denied' error.

Anyway, a last question : how can i get %appdata% in delphi ?

Thank you very much for your time.

Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact