Reputation: 39
I have an Inno Setup script with silent install options that have procedure that uses ExtractTemporaryFile
:
procedure SetAccessPermission(folderName : string; groupName : string );
Var
output : string;
ErrorCode : integer;
begin
ExtractTemporaryFile('EnvironmentAdjustment.exe');
ExtractTemporaryFile('EnvironmentAdjustment.exe.config');
ExtractTemporaryFile('Win32Security.dll');
ShellExec('', ExpandConstant('{tmp}\EnvironmentAdjustment.exe'),
ExpandConstant('"' + folderName + '" "' + groupName + '" '),
ExpandConstant('{tmp}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
LoadStringFromFile(ExpandConstant(resultPath + '\folderaccess.txt'), output);
Log('Result: ' + SysErrorMessage(ErrorCode) + ')');
end;
That procedure is used several times in the code:
SetAccessPermission('{app}\WebSite\imagescache', groupForSettingReadWritePermisions);
SetAccessPermission('{app}\WebSite\formscache', groupForSettingReadWritePermisions);
But on the second use exception is thrown:
The process cannot access the file because it is being used by another process.
I've added some logs and found that it definitely fails on the first ExtractTemporaryFile
executing. No any existing processes don't use that file, so I think that's something inside in Inno Setup. I wasted too much time to understand what goes wrong, but I have not idea still. Also, this issue occurs only on single machine with Windows Server 2012 R2 (and even there such problem started only some time ago), script is executed properly on all others, so that adds more questions.
Upvotes: 0
Views: 840
Reputation: 202118
As @Andrew commented, the file is most likely locked by some antivirus or something similar. Use Process Explorer/Process Monitor to check, what process is using the file.
Anyway, it's waste to extract the files multiple times. Extract them on the first use only:
if not FileExists(ExpandConstant('{tmp}\EnvironmentAdjustment.exe')) then
begin
ExtractTemporaryFile('EnvironmentAdjustment.exe');
ExtractTemporaryFile('EnvironmentAdjustment.exe.config');
ExtractTemporaryFile('Win32Security.dll');
end;
Or do what Inno Setup does: Retry the extraction after small pause, when it fails.
Upvotes: 1