开发者

Is there way to determine if a file has been executed or not in C#?

I'm looking for a way to determine if a file has been executed or not. I've looked a bit into FileInfo's LastAccessTime but this doesn't seem to change when a file is executed. I've also looked into FileSystemWatcher but thi开发者_如何学运维s also doesn't seem to offer a solution. Is there such a thing as a file execution listener or is there another way? If it helps, i'm looking to write a folder listener that renames an .avi file within it after it has been watched/executed.


There is a distinction between file being "executed" (e.g. a portable executable file, like an "exe") and a file being "accessed" (e.g. an AVI file that is "played" by another exe).

It sounds like you are looking in the right place and you will want the "LastAccessTime" but, be aware that resolution of the Access time is dependent on the file system... On NTFS it's a full date/time, on FAT it's just the date (hence it won't change if it's already been accessed that day.)


Actually, LastAccessTime might be what you want, since AVI files aren't "executed", only opened. I have, in the past, used it for exactly the purpose you describe, but not programmatically.

Just for the sake of completeness: Windows does not keep execution history, at least not publicly.

Edited to add:

According to MSDN, LastAccessTime is your best shot, however:

Note This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system.

But this is followed a few lines later by:

To get the latest value, call the Refresh method.

(This refers to FileSystemInfo.Refresh.)

It's all a little obtuse, if it doesn't work exactly as documented I wouldn't be surprised.


Hmmm, I'm not too sure about finding out if a file has be run, but what might be a better approach would be to monitor the media player to determine when a video has finished playing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜