Application cant access file on startup

  

I’m doing an application(XE6 , Firemonkey) to synchronize files between a shared folder and a computer/s. This application checks every x hours if there are new files to be synchronized, and it starts on windows start-up.

I can do everything, my application starts on start-up, and it does the synchronization, as long as i’m the one starting it. Whem the application auto starts on start up it gives me an exception “EINOUTERROR” – File Access Denied.
On starting the application reads a small .txt file to set up it self (shared folder location, rate of synchronization etc), my guess is that since its the windows starting the app runs it without privileges to read the .txt, but even after changing the .txt permissions to full control on everyone it gives the same error.

File open code:

AssignFile(myFile,’Dados.txt’);

if FileExists(‘Dados.txt’) then
Append(myFile)
else
Rewrite(myFile);

FileMode := fmOpenRead;
Reset(myFile);

Code of placing the app on startup programs :

procedure TSyncM.RunOnStartup(const sCmdLine: string; bRunOnce: boolean; Remove: Boolean) ;
var sKey: string;
Section: string;
const ApplicationTitle = ‘GEN4Sync’;
begin
if (bRunOnce) then
sKey := ‘Once’
else
sKey := ”;
Section := ‘Software\Microsoft\Windows\CurrentVersion\Run’ + sKey + #0;
with TRegIniFile.Create(”) do
try
RootKey := HKEY_CURRENT_USER;
if Remove then
DeleteKey(Section, ApplicationTitle)
else
WriteString(Section, ApplicationTitle, sCmdLine) ;
finally
Free;
end;
end;

If i comment the piece of code that calls the reading of that .txt my app starts and executes well, but i don’t want to set it up everytime.
Thanks in advance

Comments are closed.