Live monitoring of user file processes

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 603
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Live monitoring of user file processes

Post by mrcoollion » Mon Jul 27, 2015 12:46 pm

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)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Live monitoring of user file processes

Post by Simon » Tue Jul 28, 2015 4:10 am

Hi Paul,
Checkout the "files" (detailed) function in the dictionary.
File Remove would be the one you have to code most for.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

mrcoollion
Posts: 603
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Live monitoring of user file processes

Post by mrcoollion » Tue Jul 28, 2015 10:28 am

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

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: Live monitoring of user file processes

Post by dave.kilroy » Tue Jul 28, 2015 2:10 pm

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
"...this is not the code you are looking for..."

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Live monitoring of user file processes

Post by Simon » Tue Jul 28, 2015 6:30 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

mrcoollion
Posts: 603
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Live monitoring of user file processes

Post by mrcoollion » Wed Jul 29, 2015 7:26 am

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

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Live monitoring of user file processes

Post by Klaus » Wed Jul 29, 2015 2:29 pm

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! :D


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8424
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Live monitoring of user file processes

Post by FourthWorld » Wed Jul 29, 2015 2:56 pm

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.
Richard Gaskin
LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mrcoollion
Posts: 603
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Live monitoring of user file processes

Post by mrcoollion » Wed Jul 29, 2015 9:05 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Live monitoring of user file processes

Post by Simon » Wed Jul 29, 2015 9:38 pm

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")
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

mrcoollion
Posts: 603
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Live monitoring of user file processes

Post by mrcoollion » Thu Jul 30, 2015 10:03 am

Excellent idea. This might work :D

I will dive into this to see what I can achieve with power shell commands and the tasklist.

Thanks ....!

mrcoollion
Posts: 603
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Live monitoring of user file processes

Post by mrcoollion » Thu Jul 30, 2015 3:49 pm

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.
Last edited by mrcoollion on Mon Aug 17, 2015 3:37 pm, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8424
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Live monitoring of user file processes

Post by FourthWorld » Thu Jul 30, 2015 6:10 pm

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.
Richard Gaskin
LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Windows”