Friday, 15 March 2013

delphi - Checking if the file is in use and by which application? -



delphi - Checking if the file is in use and by which application? -

trying utilize below mentioned approach more details locked file.

is file in use

function getfileinuseinfo(const filename : widestring) : ifileisinuse; var rot : irunningobjecttable; mfile, enumindex, prefix : imoniker; enummoniker : ienummoniker; monikertype : longint; unkint : iinterface; begin result := nil; olecheck(getrunningobjecttable(0, rot)); olecheck(createfilemoniker(pwidechar(filename), mfile)); olecheck(rot.enumrunning(enummoniker)); while (enummoniker.next(1, enumindex, nil) = s_ok) begin olecheck(enumindex.issystemmoniker(monikertype)); if monikertype = mksys_filemoniker begin if succeeded(mfile.commonprefixwith(enumindex, prefix)) , (mfile.isequal(prefix) = s_ok) begin if succeeded(rot.getobject(enumindex, unkint)) begin if succeeded(unkint.queryinterface(iid_ifileisinuse, result)) begin result := unkint ifileisinuse; exit; end; end; end; end; end; end;

but phone call

unkint.queryinterface(iid_ifileisinuse, result)

always returns e_nointerface.

platform: windows 7 32 bit-os, opening word files , .msg files.

checked opening files explorer , trying delete. shows proper details application in file opened. in application, seek display info application in file opened. when trying cast pointer ifileisinuse interface, queryinterface calls fails homecoming code e_nointerface means object in rot not implement ifileisinuse. afasik, ms office files implements ifileisinuse

any thought wrong here?

in fact code works fine. problem programs testing against not implement ifileisinuse. when scheme returns e_nointerface accurate. interface not implemented.

i tested file in utilize sample sdk. files added rot application, implement ifileisinuse, picked code. on other hand, files opened acrobat 8 , word 2010 not.

the conclusion draw ifileisinuse fine thought in principle, not much utilize if applications don't back upwards it. , appears there major applications not.

it clear need utilize 1 or more of other mechanisms observe application has file locked when find ifileisinuse not implemented.

delphi delphi-2009 windows-api-code-pack

No comments:

Post a Comment