Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Change Triggers...
#1
Is it possible to have a file change trigger in an executable?
Or to assign a trigger with windows?

Obviously it is possible to do it because QM does it!

Thanks,
Jimmy Vig
#2
I know 2 or 3 ways:

1. ReadDirectoryChangesW. QM uses it for file triggers.
2. SHChangeNotifyRegister. QM uses it to monitor scheduled tasks.
3. Change Journals. Did not try it.
#3
For ReadDirectoryChangesW, is it just running in a loop while QM is active?

Could you give an example so I can see for sure that I'm thinking about it the right way.

Thanks so much Smile

Jimmy Vig
#4
ReadDirectoryChangesW can wait, or can use event and you can wait for the event.

SHChangeNotifyRegister is easier. I think it is better to use if you for example need to be notified that something modified a file that is opened in your editor.

Now I cannot give examples. Try to find C++ examples. In QM would be similar.
#5
MSDN Page (SHChangeNotifyRegister)

Not sure what to do with any of this...I'm downloading the Windows SDK because apparently there are examples there. Wish they could just be online. Whatever...9hrs later...

Anyone have other good resources for examples on how to use this?

found this little bit, but not sure about it???
Code:
Copy      Help
BYTE Read_Buffer[ 4096 ];

  ...
  ReadDirectoryChangesW(...Read_Buffer, 4096,...);
  ...

  CFileNotifyInformation notify_info( Read_Buffer, 4096);
  do{
        switch( notify_info.GetAction() )
        {
        case xx:
            notify_info.GetFileName();
        }

  while( notify_info.GetNextNotifyInformation() );
#6
Function dlg_shell_notifications
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

#compile "__CFileChangeMonitor"

if(!ShowDialog("dlg_shell_notifications" &dlg_shell_notifications 0)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Static 0x54000000 0x0 2 22 220 20 "Don't close this dialog. Open My Documents folder and change something (rename files, etc). Look in QM output."
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,CFileChangeMonitor- t_fcm ;;declare one thread variable for each folder you will monitor
,if(!t_fcm.Register(hDlg "$personal$")) ;;monitor My Documents folder
,,mes "failed to set file change notifications" "" "!"
,
,case WM_DESTROY
,t_fcm.Unregister
,case WM_COMMAND goto messages2
,
,case WM_USER+145
,;wParam is SHNOTIFYSTRUCT containing pidl of the file or folder (depending on event). If renamed, also contains the new pidl.
,;lParam probably is wEventId of SHChangeNotify (documented in MSDN library)
,SHNOTIFYSTRUCT& n=+wParam
,str s1 s2
,if(n.dwItem1) PidlToStr +n.dwItem1 &s1
,if(n.dwItem2) PidlToStr +n.dwItem2 &s2
,out "0x%08X %s %s" lParam s1 s2
,
,;notes:
,;SHChangeNotifyRegister documentation says that sometimes multiple messages are combined into 1.
,;Also, sometimes more than 1 notification may be sent for the same event.
,;Sometimes notifications may be not sent. Eg if an app forgets to call SHChangeNotify after it makes a change, and OS does not call it too. Especially in older OS.
,;I don't know, are dwItem1 and dwItem2 always pidls. Maybe sometimes they can be paths or friendly names, like when calling SHChangeNotify with SHCNF_PATH etc.
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Attached Files
.qml   CFileChangeMonitor.qml (Size: 4.17 KB / Downloads: 215)
#7
Thanks bunches!!!

This seems to work good when a file is created, deleted, or renamed. VERY slow response when file is modified and only outputs Folder name.

Will work well for some of the applications I am working developing.

Nowhere near the speed of QM file mod trigger :roll:

So if I can't speed it up and boost the reliability I'll stick with QM running in the background.

How many machines can I run QM with one license? I might have to buy more Smile

Thanks,
Jimmy Vig
#8
If need speed and reliability, use ReadDirectoryChangesW. But it is not so easy. Now I cannot give example.

Licenses:
Macro Macro630
Code:
Copy      Help
QmHelp "IDP_LICENSE"
#9
A complex question which is probably to time consuming to implement, but here goes...
It's a sort of follow up question from topic: https://www.quickmacros.com/forum/showth...p?tid=6501

QUESTION:
Is it possible to track the file changes in relation to a QM control?
In other words, I have shdocvw control which points to a folder, I want to track the changes the shdocvw control makes.
(Not in relation to the folder the shdocvw points, but the changes the shdocvw control makes when running)

I have used the trigger $f 0x449 "C:\" from the above mentioned topic and tracked the changes to the folder:

C:\Users\r0n\AppData\Local\Microsoft\Windows\AppCache
C:\Users\r0n\AppData\LocalLow\Microsoft\CryptnetUrlCache\MetaData
C:\Users\r0n\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
C:\Users\r0n\AppData\Local\Microsoft\Internet Explorer
C:\Users\r0n\AppData\Local\Microsoft\Windows\INetCache\IE

I was hoping the above example in this thread could be applied (constrained) to an control (shdocvw):

Function dlg_shell_notifications_shdoc
Code:
Copy      Help
#compile "__CFileChangeMonitor"
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;10 ActiveX 0x54030000 0x0 5 20 150 104 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "10"
str ax10SHD
ax10SHD="$personal$"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,CFileChangeMonitor- t_fcm ;;declare one thread variable for each folder you will monitor
,if(!t_fcm.Register(hDlg "$personal$")) ;;monitor My Documents folder
,,mes "failed to set file change notifications" "" "!"
,
,case WM_DESTROY
,t_fcm.Unregister
,case WM_COMMAND goto messages2
,
,case WM_USER+145
,;wParam is SHNOTIFYSTRUCT containing pidl of the file or folder (depending on event). If renamed, also contains the new pidl.
,;lParam probably is wEventId of SHChangeNotify (documented in MSDN library)
,SHNOTIFYSTRUCT& n=+wParam
,str s1 s2
,if(n.dwItem1) PidlToStr +n.dwItem1 &s1
,if(n.dwItem2) PidlToStr +n.dwItem2 &s2
,out "0x%08X %s %s" lParam s1 s2
,
,;notes:
,;SHChangeNotifyRegister documentation says that sometimes multiple messages are combined into 1.
,;Also, sometimes more than 1 notification may be sent for the same event.
,;Sometimes notifications may be not sent. Eg if an app forgets to call SHChangeNotify after it makes a change, and OS does not call it too. Especially in older OS.
,;I don't know, are dwItem1 and dwItem2 always pidls. Maybe sometimes they can be paths or friendly names, like when calling SHChangeNotify with SHCNF_PATH etc.
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Again if to complex/time consuming, I understand.
I can always continue to use the alternative cleanup solution from the original topic.

(The reason for this method is to be "100%" sure I am cleaning up traces of changes the control makes.)
#10
in relation to a QM control - probably not.
Should be possible to track file write operations of current process, but I don't know how.
#11
Ok! Thanks!


Forum Jump:


Users browsing this thread: 1 Guest(s)