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

I am looking for a way to determine if a file was executed or not. I twisted a bit in FileInfo LastAccessTime, but that doesn't seem like a file change. I also looked in FileSystemWatcher, but this also does not seem to be a solution. Is there such a thing as a file execution listener, or is there another way? If this helps, I am looking to write a folder listener that renames the .avi file inside it after it has been viewed / executed.

+4
source share
3 answers

There is a difference between an executable file (for example, a portable executable file, for example "exe"), and a file that is "accessed" (for example, an AVI file that is being "played" by another exe).

It looks like you are looking at the right place and you need “LastAccessTime”, but keep in mind that access time resolution depends on the file system ... On NTFS, this is the full date / time, on FAT it is just the date (therefore, it will not change if this day has already been addressed to her.)

+1
source

Actually, LastAccessTime may be what you want, since AVI files are not executed, they only open. In the past, I used it precisely for the purpose you are describing, but not programmatically.

Just for completeness: Windows does not save the execution history, at least not publicly.

Edited to add:

According to MSDN , LastAccessTime is your best snapshot:

Note. This method may return an inaccurate value because it uses its own functions whose values ​​cannot be constantly updated by the operating system.

But this follows a few lines later:

To get the last value, call the Refresh method.

(This applies to FileSystemInfo.Refresh .)

All this is a little stupid, if it does not work exactly as described in the document, I will not be surprised.

+1
source

Hmmm, I'm not too sure that I will find out if the file was launched, but it would be best to monitor the media player to determine when the video ended.

0
source

Source: https://habr.com/ru/post/1312104/


All Articles