【发布时间】:2015-05-22 12:35:14
【问题描述】:
我正在做一个应用程序(XE6,Firemonkey)来同步共享文件夹和计算机之间的文件。此应用程序每 x 小时检查一次是否有新文件要同步,并在 Windows 启动时启动。
我可以做任何事情,我的应用程序在启动时启动,它会进行同步,只要我是启动它的人。当应用程序在启动时自动启动时,它给了我一个异常“EINOUTERROR” - 文件访问被拒绝。 在启动应用程序时会读取一个小的 .txt 文件以自行设置(共享文件夹位置、同步率等),我的猜测是,由于启动应用程序的 Windows 运行它时没有读取 .txt 的权限,但即使在将 .txt 权限更改为对每个人的完全控制它会给出相同的错误。
文件打开代码:
AssignFile(myFile,'Dados.txt');
if FileExists('Dados.txt') then
Append(myFile)
else
Rewrite(myFile);
FileMode := fmOpenRead;
Reset(myFile);
将应用置于启动程序的代码:
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;
如果我注释调用读取该 .txt 的代码段,我的应用程序启动并执行良好,但我不想每次都设置它。 在此先感谢
【问题讨论】:
标签: delphi startup firemonkey delphi-xe6