最近我遇到了文件创建问题,当我的delphi应用程序使用开始菜单或桌面快捷方式执行时,即使它以管理员身份运行.如果我直接从其文件夹中以管理员身份运行它,则没有问题.
基本上我已经创建了一个delphi 32位GUI程序,它使用zipforge归档程序构建SFX归档.如果我从例如C:\ myProgramFolder运行程序,应用程序正常运行并将存档构建到指定的输出文件夹,但是,当我使用快捷方式运行它时,我得到的是I/O 105.我想这应该是有问题的东西与Win7安全策略有关,但也许有人曾经处理过这类问题,所以我非常感谢任何建议.
这是一个导致I/O 105的过程:
quickfix.ini是一个文件,用于为SFX存根提供显示信息,这就是它存在的原因
procedure TfrmMain.Buildinstaller1Click(Sender: TObject);
var
presentPath: string;
begin
presentPath := ExtractFilePath(Application.ExeName);
SynEdit1.Lines.SaveToFile(presentPath + '\quickfix.ini');
CopyFile(pchar(presentPath + '\quickfix.ini'),
pchar(edSourcePath.Text + '\quickfix.ini'), false);
CopyFile(pchar(presentPath + '\bin\Uninstall.exe'),
pchar(edSourcePath.Text + '\Uninstall.exe'), false);
DeleteFile(presentPath + '\quickfix.ini');
if (edSourcePath.Text <> '') and (edOutPutPath.Text <> '') then begin
saveExe.InitialDir := edOutPutPath.Text;
if saveExe.Execute() then begin
frmProgress.Show;
try
// this is a line where the problem begins
with archiver do begin
TempDir := GetTempDirectory;
FileName := saveExe.FileName;
OpenArchive(fmCreate);
BaseDir := edSourcePath.Text;
AddFiles('*.*');
CloseArchive();
end;
except
on E: Exception do begin
writeln('Exception: ', E.Message);
Readln;
frmProgress.ProgressBar1.Position := 0;
frmProgress.Close;
end;
end;
end;
MessageDlg('QuickFix install successfully built!', mtInformation,
[mbOk], 0);
frmProgress.Close;
end else begin
MessageDlg('Source and/or output path not set. Please review.',
mtInformation, [mbOk], 0);
end;
end;
Run Code Online (Sandbox Code Playgroud)
自10年前发布的Vista启用UAC以来,即使是管理员用户也默认使用受限权限运行.仅当运行升级的进程时,该进程的用户令牌才会获得管理员权限.
程序文件文件夹具有安全设置,这意味着标准用户无法写入它们.您需要将文件保存到程序文件文件夹以外的文件夹中.应用程序数据文件夹是一个明显的选择.
如果这个一般性答案没有完全解释您的问题,那么请提供一个完整的程序,准确地演示您的场景.
| 归档时间: |
|
| 查看次数: |
658 次 |
| 最近记录: |