5

I am trying to write Memo text to a .txt file in Delphi XE3, in Windows 8, but for some reason when I run the program in the IDE it works (the temp .exe is on my D: drive) but when I copy my program to C:\Myprogram.exe it gives error "Access denied" so i cant write anywhere on C:\

I already tried making a manifest and that did not work.

P.S.: I don't want to run my program as an administrator and when I do run as admin it works.

Kromster
  • 7,181
  • 7
  • 63
  • 111
Kobus Vdwalt
  • 347
  • 1
  • 7
  • 20

1 Answers1

12

If you're not an administrator, you cannot write in certain places. That is to protect you (or your users) and it's a rule you cannot circumvent without disabling UAC, which you should't rely on (if it's possible at all in Windows 8).

Pick a location you can write to, for instance a Documents folder or another special folder for storing application data.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • Oh sorry i feel stupid now because i tried everywhere but a documents folder, well it works its just a pity i cant write to program files. – Kobus Vdwalt Dec 23 '12 at 19:01
  • 9
    Yeah, many people feel that way, but it's for the best, really. :) – GolezTrol Dec 23 '12 at 19:02
  • You'd better really avoid using global variables and global files until absolutely inevitable and necessary. http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx – Arioch 'The Dec 24 '12 at 13:57
  • Yes, Program Files and Application Data have been separated for this reason, specifically to prevent malicious programs from writing to the Program Files in attempt to alter some software, etc. – Jerry Dodge Dec 25 '12 at 16:05