-5

I'm trying to have my application write into a text file. When the program is ran on a windows admin account it works but not when ran with a regular windows account. The application is not running as admin both times. Can the account the program is running on affect writing rights? Is there a way to work around it?

Both the directory and the file have write permission for any user.

I'm using the Append and WriteLn procedures from System.

The file is found in the Program Files dir although we change the access to our own directory to be writeable by regular users.

EDIT: Here's the code

var
f: TextFile;

AssignFile(f, sFile);

if not FileExists(sfile) then
begin
    Rewrite(f);
end
else
begin
    //Will append to the file
    Append(f);
end;

Writeln(f, sInfo);

Flush(f);
CloseFile(f);
Cauchemar
  • 119
  • 2
  • 12
  • Show us the code that opens the file. And you may consider using streams and stream writers instead of old fashioned plain Pascal routines like Writeln. But again: show us the code that opens the file and the code that tries to write to it. Show a simple [MCVE]. – Rudy Velthuis May 13 '18 at 23:24
  • @RudyVelthuis I added the code. – Cauchemar May 13 '18 at 23:44
  • 2
    You added some code, but not your code. That does not compile. And what is sInfo? – Rudy Velthuis May 13 '18 at 23:57
  • 2
    Check effective permissions. – Sertac Akyuz May 14 '18 at 00:41
  • "does not work" is not a useful problem description. What are the **exact** symptoms of it not working? – MartynA May 14 '18 at 06:44
  • Seems like it's working exactly how it's supposed to work. You don't have permission to write to the program files. Been like this for quite some time. – Jerry Dodge May 14 '18 at 13:22
  • Writing into the `Program Files`directory is not allowed for regular users, but even for admin users it is not recommended for software to write in this folder. That has been like that for some time. Dont fight windows, work along with it – GuidoG May 14 '18 at 15:14

1 Answers1

1

Yes, the account the program is run under determines where it can and can't write to.

Non-admin users can't write to program files, and a lot of other places.

You'll need to do some research to find out where a non-admin user can write to, but start with: System.IOUtils.TPath.GetHomePath

Mike Dixon
  • 149
  • 1
  • 7