Page 1 of 1
Live monitoring of user file processes
Posted: Mon Jul 27, 2015 12:46 pm
by mrcoollion
Is there any way in livecode to monitor file related processes from a user (in Windows but if possible also other platforms).
I would like to write an application (service) based upon the following occuring processes at a user.
- File Create
- File Open
- File Change
- File Close
- File Remove
Kind regards,
Paul
(Developer ELMNTRE)
Re: Live monitoring of user file processes
Posted: Tue Jul 28, 2015 4:10 am
by Simon
Hi Paul,
Checkout the "files" (detailed) function in the dictionary.
File Remove would be the one you have to code most for.
Simon
Re: Live monitoring of user file processes
Posted: Tue Jul 28, 2015 10:28 am
by mrcoollion
Hi Simon,
Thanks for the reply and suggestion however I cannot find a command or solution in the "files" function in the dictionary which I can use for my purpose.
To clarify: I want to build a service that monitors in Windows when a user opens a file, closes a file, changes a file or removes/moves a file. Those files can be opened by other (non LiveCode) applications like word or excel or any other application. As soon as one of those events occurs I want to use this trigger within my application (running as a service in the users OS).
Maybe I did not look at the correct place or information, if not please let me know.
Kind regards,
Paul
Re: Live monitoring of user file processes
Posted: Tue Jul 28, 2015 2:10 pm
by dave.kilroy
I think Simon means that the 'files' function gets you the file names (and the 'detailed files' gets you - you guessed it - lots of detailed information about the files in a particular folder).
Once you know how to get that information you could run a simple timed comparison to see if something changes (or have I misunderstood you?):
Code: Select all
local sFileList
on mouseUp
--first set up which directory to monitor
--secondly get an initial list of files in it
--and thirdly, start running comparisons
answer folder "Select a folder to monitor"
if it is empty then exit mouseUp
set the directory to it
put the files into sFileList
send checkFiles to me in 2 secs
end mouseUp
on checkFiles
if the files is not sFileList then
--here you can have code that compares 'the files' with sFileList
--line-by-line to find out which file has changed - you can then
--do whatever it is you want to do with this information...
answer "Something has changed!"
put the files into sFileList
end if
send checkFiles to me in 2 secs
end checkFiles
Re: Live monitoring of user file processes
Posted: Tue Jul 28, 2015 6:30 pm
by Simon
Hi Paul,
Here is the link to the "files" function in the API
https://livecode.com/resources/api/#liv ... ript/files
And here is a little lesson
http://lessons.runrev.com/m/4071/l/1663 ... ers-part-1
For Remove you'll have to store the filenames in a DB or simple text file. I guess you'd want a DB anyways so you'd just stick all the "detailed files" information in there.
Simon
Re: Live monitoring of user file processes
Posted: Wed Jul 29, 2015 7:26 am
by mrcoollion
Hi Dave and Simon,
Thanks for you help , however I do not think the files option would work for the business application I want to build. Mainly because there can be 100's to 1000's of files in the many folders a business user is able to access with his or her permissions. Scanning all these folders every x seconds would be too memory and processor intensive to do and probably also to slow.
I at least need to be able to see in the the users active memory which files the user has open. If I am able to do that than I can check for those files with the files functions in livecode and do anything I need.
For example SysInternals tool (now from Microsoft) is able to do this.
(
https://technet.microsoft.com/en-us/sys ... 96653.aspx )
(
https://technet.microsoft.com/en-us/sys ... s/bb896645 download url)
And thanks for the code sample

.
Regards,
Paul
Re: Live monitoring of user file processes
Posted: Wed Jul 29, 2015 2:29 pm
by Klaus
Hi Paul,
I'm afraid what you want cannot be done with the build-in means of Livecode.
You will need an external that digs into the innards of the target OS!
Best
Klaus
Re: Live monitoring of user file processes
Posted: Wed Jul 29, 2015 2:56 pm
by FourthWorld
Hello Paul -
Klaus is right: currently LiveCode provides no direct support for those specific APIs, so while they would be super-cool for making file-syncing and other tools we'd have to write an external that uses those APIs to get that functionality in LC 7 and earlier.
With LiveCode v8, however, there's a new language being developed for making those types of extensions without having to use C++, LiveCode Builder. In addition to providing many new slightly lower-level options for making GUI Widgets, it provides access to native OS APIs, so you could write a library in LiveCode Builder to handle that for v8, and likely more simply than would be required to do that in C++ using the externals API.
Re: Live monitoring of user file processes
Posted: Wed Jul 29, 2015 9:05 pm
by mrcoollion
Thanks for your clear replies to my question and I have got my answer.
I will be waiting for LC8 to arrive and then dive into this matter.
Thanks again.....
Kind regards,
Paul
Re: Live monitoring of user file processes
Posted: Wed Jul 29, 2015 9:38 pm
by Simon
WOW!
Code: Select all
on mouseUp
put shell("powershell.exe get-process")
end mouseUp
Things I can do just by trying.
Simon
Edit; but easy put shell("tasklist -v")
Re: Live monitoring of user file processes
Posted: Thu Jul 30, 2015 10:03 am
by mrcoollion
Excellent idea. This might work
I will dive into this to see what I can achieve with power shell commands and the tasklist.
Thanks ....!
Re: Live monitoring of user file processes
Posted: Thu Jul 30, 2015 3:49 pm
by mrcoollion
Based upon Simons idea and some tests I found a way to get user processes in detail.
The problem was that if an application (e.g. word) has more than one document open I could not see that with tasklist command.
I tried handle.exe from sysinternals (now from Microsoft).
Downloadable at:
https://technet.microsoft.com/en-us/sys ... 96655.aspx
For test I placed the executable in the root
With this executable I am able to get the information I need.
Code: Select all
on mouseUp
put "C:\handle.exe -p winword.exe" into commandstring
put shell(commandstring)
end mouseUp
Now I need to find the fastest way to filter the documents (e.g. ending with docx) and get the path-name into a variable.
Because sysinternals has more tools like this this might open some interesting possibilities for some.
So this is a good start.
Thanks.
Re: Live monitoring of user file processes
Posted: Thu Jul 30, 2015 6:10 pm
by FourthWorld
Kudos to Simon for suggesting PowerShell. I so seldom use Windows I forget they now ship it with a usable scripting language. Good call - I should spend more time with it myself.