Discussion:
File access denied
(too old to reply)
viana
2008-03-24 22:33:20 UTC
Permalink
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
Viana
Remy Lebeau (TeamB)
2008-03-24 22:41:13 UTC
Permalink
Post by viana
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.
Post by viana
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
viana
2008-03-24 23:20:38 UTC
Permalink
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
Remy Lebeau (TeamB)
2008-03-24 23:25:24 UTC
Permalink
Post by viana
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
viana
2008-03-25 00:07:05 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by viana
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.
Remy Lebeau (TeamB)
2008-03-25 17:46:30 UTC
Permalink
Post by viana
Problem is i keep some files hide in Windows or System32 directory
Don't do that, either. Treat any system folder as read-only. They are
locked down for security and policy reasons. The OS sets asside special
folders for applications to write and store files to. Use them. They are
there for a reason.
Post by viana
This is usefull to help avoid cracking
No, it is not. Any decent cracker can get past that quite easily.
Post by viana
as if i put these files on a appdata, it's much easier for a
cracker to find it.
Any file system monitor (such as SysInternals' free FileMon tool) can tell a
cracker every file your app accesses, no matter where it is located. Trying
to hide files is a pretty useless practice.
Post by viana
how can i get %appdata% in delphi ?
Please go re-read my original reply. I already told you how to do that.


Gambit
viana
2008-03-25 20:36:34 UTC
Permalink
Ok, thank you very much.
Post by Remy Lebeau (TeamB)
Post by viana
Problem is i keep some files hide in Windows or System32 directory
Don't do that, either. Treat any system folder as read-only. They are
locked down for security and policy reasons. The OS sets asside special
folders for applications to write and store files to. Use them. They are
there for a reason.
Post by viana
This is usefull to help avoid cracking
No, it is not. Any decent cracker can get past that quite easily.
Post by viana
as if i put these files on a appdata, it's much easier for a
cracker to find it.
Any file system monitor (such as SysInternals' free FileMon tool) can tell a
cracker every file your app accesses, no matter where it is located. Trying
to hide files is a pretty useless practice.
Post by viana
how can i get %appdata% in delphi ?
Please go re-read my original reply. I already told you how to do that.
Gambit
Loading...