Ну, самое простое, попробовать открыть его для чтения. Если файл не открывается, значит он чем то занятКак с помощью Inno узнать занят ли файл чем либо
В теории я все это понимаю, но как через код, не могу сообразить.Ну, самое простое, попробовать открыть его для чтения. Если файл не открывается, значит он чем то занят
К чему это?Exec(ExpandConstant('{sys}\taskkill.exe'), ' /F /IM pzlib.exe', '', SW_HIDE, ewWaitUntilTerminated, i);
ХЗ как по профессиональности написания, но можно так:Как с помощью Inno узнать занят ли файл чем либо
[Setup]
AppName=MyProg
AppVerName=MyProg
DefaultDirName={pf}\MyProg
OutputDir=.\
[Code]
const
OPEN_EXISTING = 3;
FILE_SHARE_WRITE = 2;
GENERIC_WRITE = $40000000;
INVALID_HANDLE_VALUE = 4294967295;
function CreateFile(lpFileName: string; dwDesiredAccess, dwShareMode,
lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle;
external 'CreateFileW@kernel32.dll stdcall';
function CloseHandle(hObject: THandle): BOOL;
external 'CloseHandle@kernel32.dll stdcall';
function FileStatus(const AFileName: string): Boolean;
var
FileHandle: THandle;
begin
Result:= False;
FileHandle:= CreateFile(AFileName, GENERIC_WRITE, FILE_SHARE_WRITE, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if FileHandle <> INVALID_HANDLE_VALUE then
try
Result:= True;
finally
CloseHandle(FileHandle);
end;
end;
function InitializeSetup(): Boolean;
begin
if FileExists(ExpandConstant('{src}\test.wav')) then
if FileStatus(ExpandConstant('{src}\test.wav')) then
MsgBox('Файл свободен!', mbInformation, MB_OK)
else MsgBox('Файл занят в другой программе!', mbInformation, MB_OK);
Result:= False;
end;
[Setup]
AppName=MyProg
AppVerName=MyProg
DefaultDirName={pf}\MyProg
OutputDir=.\
[Code]
function FileStatus(const AFileName: string): Boolean;
begin
Result:= True;
with TFileStream.Create(AFileName,fmShareExclusive) do
try
free;
except
Result:= False;
end;
end;
function InitializeSetup(): Boolean;
begin
if FileExists(ExpandConstant('{src}\test.wav')) then
if FileStatus(ExpandConstant('{src}\test.wav')) then
MsgBox('Файл свободен!', mbInformation, MB_OK)
else MsgBox('Файл занят в другой программе!', mbInformation, MB_OK);
Result:= False;
end;
По MP3 оно работает: Скринmp3 все время выдает файл свободен
if ISFileInUse ("D: \TestFile\setup1.exe") then
MsgBox ('file is in use', mbConfirmation, MB_OK);
function ISDirEmpty (Dir: widestring): Boolean; external 'ISDirEmpty @ files: ISFilePlus.dll stdcall';
function ISDirWriteable (Dir: widestring): Boolean; external 'ISDirWriteable @ files: ISFilePlus.dll stdcall';
function ISExistSubDirs (Dir: widestring): Boolean; external 'ISExistSubDirs @ files: ISFilePlus.dll stdcall';
function ISDirSizeMB (Dir: widestring): cardinal; external 'ISDirSizeMB @ files: ISFilePlus.dll stdcall';
function ISDirSizeStr (Dir: widestring): widestring; external 'ISDirSizeStr @ files: ISFilePlus.dll stdcall';
function ISOpenFolder (ADir, ATitle: widestring): widestring; external 'ISOpenFolder @ files: ISFilePlus.dll stdcall';
function ISCopyDir (Dir, dest: widestring; CopyRoot, Show: Boolean): Boolean; external 'ISCopyDir @ files: ISFilePlus.dll stdcall';
function ISMoveDir (Dir, dest: widestring; MoveRoot, Show: Boolean): Boolean; external 'ISMoveDir @ files: ISFilePlus.dll stdcall';
function ISRenameDir (Dir, dest: widestring; Show: Boolean): Boolean; external 'ISRenameDir @ files: ISFilePlus.dll stdcall';
function ISDeleteDir (Dir: widestring; DeleteRoot, permanent, Show: Boolean): Boolean; external 'ISDeleteDir @ files: ISFilePlus.dll stdcall';
function ISDirCreationTime (ADir: widestring): widestring; external 'ISDirCreationTime @ files: ISFilePlus.dll stdcall';
function ISDirLastAccessedTime (ADir: widestring): widestring; external 'ISDirLastAccessedTime @ files: ISFilePlus.dll stdcall';
function ISDirLastWrittenTime (ADir: widestring): widestring; external 'ISDirLastWrittenTime @ files: ISFilePlus.dll stdcall';
procedure ISDirChangeTime (ADir, ATime: widestring; DoRoot: boolean); external 'ISDirChangeTime @ files: ISFilePlus.dll stdcall';
function ISFindFiles (APath, FileMask: widestring): longint; external 'ISFindFiles @ files: ISFilePlus.dll stdcall';
function ISFileCount (FindHandle: longint): integer; external 'ISFileCount @ files: ISFilePlus.dll stdcall';
function ISPickFile (FindHandle: longint; AIndex: integer): widestring; external 'ISPickFile @ files: ISFilePlus.dll stdcall';
procedure ISFindFree (FindHandle: longint); external 'ISFindFree @ files: ISFilePlus.dll stdcall';
function ISGetFileAttrbs (AFileName: widestring): widestring; external 'ISGetFileAttrbs @ files: ISFilePlus.dll stdcall';
function ISSetFileAttrbs (AFileName, Attrbs: widestring): boolean; external 'ISSetFileAttrbs @ files: ISFilePlus.dll stdcall';
function ISCheckFileAttrbs (AFileName: widestring; Attrb: widestring): boolean; external 'ISCheckFileAttrbs @ files: ISFilePlus.dll stdcall';
function ISClearFileAttrbs (AFileName: widestring): boolean; external 'ISClearFileAttrbs @ files: ISFilePlus.dll stdcall';
function ISFileIsDir (AName: widestring): boolean; external 'ISFileIsDir @ files: ISFilePlus.dll stdcall';
function ISFileIsHidden (Afile: widestring): boolean; external 'ISFileIsHidden @ files: ISFilePlus.dll stdcall';
function ISFileInUse (AName: widestring): boolean; external 'ISFileInUse @ files: ISFilePlus.dll stdcall';
function ISFileSizeMB (aFilename: widestring): cardinal; external 'ISFileSizeMB @ files: ISFilePlus.dll stdcall';
function ISFileSizeStr (aFilename: widestring): widestring; external 'ISFileSizeStr @ files: ISFilePlus.dll stdcall';
function ISCopyFile (AInFile, ADest: widestring; Show: boolean): boolean; external 'ISCopyFile @ files: ISFilePlus.dll stdcall';
function ISMoveFile (AInFile, ADest: widestring; Show: boolean): boolean; external 'ISMoveFile @ files: ISFilePlus.dll stdcall';
function ISRenameFile (AInFile, ADest: widestring; Show: boolean): boolean; external 'ISRenameFile @ files: ISFilePlus.dll stdcall';
function ISDeleteFile (AInFile: widestring; permanent, Show: boolean): boolean; external 'ISDeleteFile @ files: ISFilePlus.dll stdcall';
function ISFileOpen1 (AHandle: HWND; ADir, ATitle: widestring): widestring; external 'ISFileOpen1 @ files: ISFilePlus.dll stdcall';
function ISFileOpen2 (AHandle: HWND; ADir, ATitle, AFilter: widestring): widestring; external 'ISFileOpen2 @ files: ISFilePlus.dll stdcall';
function ISFileSave1 (AHandle: HWND; ADir, AFile, ATitle: widestring): boolean; external 'ISFileSave1 @ files: ISFilePlus.dll stdcall';
function ISFileSave2 (AHandle: HWND; ADir, AFile, ATitle, AFilter: widestring): boolean; external 'ISFileSave2 @ files: ISFilePlus.dll stdcall';
function ISFileVersion (Afile: widestring): widestring; external 'ISFileVersion @ files: ISFilePlus.dll stdcall';
function ISFileCreationTime (Afile: widestring): widestring; external 'ISFileCreationTime @ files: ISFilePlus.dll stdcall';
function ISFileLastAccessedTime (Afile: widestring): widestring; external 'ISFileLastAccessedTime @ files: ISFilePlus.dll stdcall';
function ISFileLastWrittenTime (Afile: widestring): widestring; external 'ISFileLastWrittenTime @ files: ISFilePlus.dll stdcall';
procedure ISFileChangeTime (AFile, ATime: widestring); external 'ISFileChangeTime @ files: ISFilePlus.dll stdcall';
да не перехватишь его, по проверке файлов. Нужно перехватывать Handle в активных процессах по адресу файла, но в случае с документами это все равно не сработает.with .rtf not