Jump to content

Recommended Posts

Posted (edited)

Is it possible to use WMI events, to monitor all the specific files of given filetype inside specific directory?

I'd find it very usefull to use simple WMI events to check for how often graphic designers in my graphic department use different illustrator .AI files.

Right now I am scanning folders using my own function and FileGetTime to check for any changes (last time accessed) and check for how usefull to us are files we have, but this is very limited.
I have to run my scrypt every single minut to get more-less accurate data, missing some of the events that already accured or unnecesarilly over-loading CPU.

Thanks in advance.

Edited by DesireDenied
Posted (edited)

Defeton, you just made me my day, works like a charm!

Turned out that I've been using an outdated Autoit and Scite and everything is in help file since I dont really know when :)
Once again, thanks.

Uhm, not sure why but I have just noticed that for some reason, it does not work on my laptop.

#include <APIFilesConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIDiag.au3>
#include <WinAPIFiles.au3>
#include <WinAPISys.au3>

Global $g_sPath = @TempDir & '\~TEST~'

DirCreate($g_sPath)
If Not FileExists($g_sPath) Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Unable to create folder.')
    Exit
EndIf

OnAutoItExitRegister('OnAutoItExit')

Local $hDirectory = _WinAPI_CreateFileEx($g_sPath, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS)
If @error Then
    _WinAPI_ShowLastError('', 1)
EndIf

Local $pBuffer = _WinAPI_CreateBuffer(0x800000)

Local $aData
While 1
    $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME), $pBuffer, 0x800000, 1)
    If Not @error Then
       If IsArray($aData) Then ConsoleWrite(StringFormat("filename:\t  %s\nreason: \t%s\n\n", $aData[1][0], $aData[1][1]))
    Else
        _WinAPI_ShowLastError('', 1)
    EndIf
WEnd

Func OnAutoItExit()
    DirRemove($g_sPath, 1)
EndFunc   ;==>OnAutoItExit

 

In this wierd battle between Win7 and another copy of Win7 in this case my script has failed to obtain any usefull information... oO
Can anyone explain how's that?

filename:      

reason:     0



filename:      

reason:     0



filename:      

reason:     0




			
				


	Edited  by DesireDenied
	
	

			
		
Posted

I am glad to help! ^^
:thumbsup:

 

  On 10/30/2014 at 9:17 PM, DesireDenied said:

In this wierd battle between Win7 and another copy of Win7 in this case my script has failed to obtain any usefull information... oO
Can anyone explain how's that?

Well, I thinking... you have the last AutoIt & Scite Version in your notebook?

You WMI Service is runing too?

Br, Detefon.

Visit my repository

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...