argumentum Posted September 1, 2024 Posted September 1, 2024 (edited) There is this tool called Everything and it lists every file in the PC and you can declare shares and ... is a good tool. They have an IPC and there are words I recognize like "FindWindow", "WM_COPYDATA", "window_proc", etc. Is written in C, tho they have examples for C#, python, VB. ...and am thinking that the example would work from AutoIt but, I don't know enough to code it myself and I'd like to have the ability to query it from my script. Here are examples: C Spoiler expandcollapse popupIPC C Example A C example to send a search query to Everything using WM_COPYDATA and retrieve the results. Note: requires Everything running in the background. Sending a query #define COPYDATA_QUERYCOMPLETE 0 BOOL sendquery(HWND hwnd,DWORD max_results,WCHAR *search_string,BOOL regex,BOOL match_case,BOOL match_whole_word,BOOL match_path) { EVERYTHING_IPC_QUERY *query; DWORD len; DWORD size; HWND everything_hwnd; COPYDATASTRUCT cds; everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS,0); if (everything_hwnd) { len = (int)wcslen(search_string); size = sizeof(EVERYTHING_IPC_QUERY) - sizeof(WCHAR) + len*sizeof(WCHAR) + sizeof(WCHAR); query = (EVERYTHING_IPC_QUERY *)HeapAlloc(GetProcessHeap(),0,size); if (query) { query->max_results = max_results; query->offset = 0; query->reply_copydata_message = COPYDATA_QUERYCOMPLETE; query->search_flags = (regex?EVERYTHING_IPC_REGEX:0) | (match_case?EVERYTHING_IPC_MATCHCASE:0) | (match_whole_word?EVERYTHING_IPC query->reply_hwnd = hwnd; CopyMemory(query->search_string,search_string,(len+1)*sizeof(WCHAR)); cds.cbData = size; cds.dwData = EVERYTHING_IPC_COPYDATAQUERY; cds.lpData = query; if (SendMessage(everything_hwnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)&cds) == TRUE) { HeapFree(GetProcessHeap(),0,query); return TRUE; } else { // Everything IPC service not running } HeapFree(GetProcessHeap(),0,query); } } else { // the everything window was not found. // we can optionally RegisterWindowMessage("EVERYTHING_IPC_CREATED") and // wait for Everything to post this message to all top level windows when its up and running. } return FALSE; } Retrieving results void DisplayPathName(TCHAR *path,TCHAR *filename) { // ... // do something with path and filename // ... } LRESULT CALLBACK window_proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { DWORD i; EVERYTHING_IPC_LIST *list switch(uMsg) { case WM_COPYDATA: { COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam; switch(cds->dwData) { case COPYDATA_QUERYCOMPLETE: list = (EVERYTHING_IPC_LIST *)cds->lpData; for(i=0;i<list->numitems;i++) { DisplayPathName(EVERYTHING_IPC_ITEMPATH(list,&list->items[i]),EVERYTHING_IPC_ITEMFILENAME(list,&list } return TRUE; } break; } } return DefWindowProc(hwnd,msg,wParam,lParam); } Python Spoiler expandcollapse popupPython An Everything SDK Python example. Created with Python 3.7.3. Note: requires Everything running in the background. test.py import ctypes import datetime import struct #defines EVERYTHING_REQUEST_FILE_NAME = 0x00000001 EVERYTHING_REQUEST_PATH = 0x00000002 EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004 EVERYTHING_REQUEST_EXTENSION = 0x00000008 EVERYTHING_REQUEST_SIZE = 0x00000010 EVERYTHING_REQUEST_DATE_CREATED = 0x00000020 EVERYTHING_REQUEST_DATE_MODIFIED = 0x00000040 EVERYTHING_REQUEST_DATE_ACCESSED = 0x00000080 EVERYTHING_REQUEST_ATTRIBUTES = 0x00000100 EVERYTHING_REQUEST_FILE_LIST_FILE_NAME = 0x00000200 EVERYTHING_REQUEST_RUN_COUNT = 0x00000400 EVERYTHING_REQUEST_DATE_RUN = 0x00000800 EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED = 0x00001000 EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME = 0x00002000 EVERYTHING_REQUEST_HIGHLIGHTED_PATH = 0x00004000 EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000 #dll imports everything_dll = ctypes.WinDLL ("C:\\EverythingSDK\\DLL\\Everything32.dll") everything_dll.Everything_GetResultDateModified.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_ulonglong)] everything_dll.Everything_GetResultSize.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_ulonglong)] #setup search everything_dll.Everything_SetSearchW("test.py") everything_dll.Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH | EVERYTHING_REQUEST_SIZE | EVERYTHING_REQUEST_DATE_MODI #execute the query everything_dll.Everything_QueryW(1) #get the number of results num_results = everything_dll.Everything_GetNumResults() #show the number of results print("Result Count: {}".format(num_results)) #convert a windows FILETIME to a python datetime #https://stackoverflow.com/questions/39481221/convert-datetime-back-to-windows-64-bit-filetime WINDOWS_TICKS = int(1/10**-7) # 10,000,000 (100 nanoseconds or .1 microseconds) WINDOWS_EPOCH = datetime.datetime.strptime('1601-01-01 00:00:00', '%Y-%m-%d %H:%M:%S') POSIX_EPOCH = datetime.datetime.strptime('1970-01-01 00:00:00', '%Y-%m-%d %H:%M:%S') EPOCH_DIFF = (POSIX_EPOCH - WINDOWS_EPOCH).total_seconds() # 11644473600.0 WINDOWS_TICKS_TO_POSIX_EPOCH = EPOCH_DIFF * WINDOWS_TICKS # 116444736000000000.0 def get_time(filetime): """Convert windows filetime winticks to python datetime.datetime.""" winticks = struct.unpack('<Q', filetime)[0] microsecs = (winticks - WINDOWS_TICKS_TO_POSIX_EPOCH) / WINDOWS_TICKS return datetime.datetime.fromtimestamp(microsecs) #create buffers filename = ctypes.create_unicode_buffer(260) date_modified_filetime = ctypes.c_ulonglong(1) file_size = ctypes.c_ulonglong(1) #show results for i in range(num_results): everything_dll.Everything_GetResultFullPathNameW(i,filename,260) everything_dll.Everything_GetResultDateModified(i,date_modified_filetime) everything_dll.Everything_GetResultSize(i,file_size) print("Filename: {}\nDate Modified: {}\nSize: {} bytes\n".format(ctypes.wstring_at(filename),get_time(date_modified_filetime),file_size.value)) Output Filename: C:\Users\python\Desktop\test.py Date Modified: 2019-06-30 19:38:03.171133 Size: 2976 bytes See Also https://stackoverflow.com/questions/252417/how-can-i-use-a-dll-file-from-python https://stackoverflow.com/questions/39481221/convert-datetime-back-to-windows-64-bit-filetime https://stackoverflow.com/questions/2330587/how-to-convert-ctypes-c-long-to-pythons-int https://stackoverflow.com/questions/45178140/returning-string-from-c-function-with-ctypes-gives-large-int-not-char-pointer ..and there are more but I figure that to code it, you'll have to download their stuff so, no use in overwhelming this thread with examples. PS: copying the example code from the CHM to this site don't look good but legible enough, I hope. Edit: they also offer a HTTP server, so I could ask "http://IPv4:port/?search=find+this&sort=date_modified&ascending=0&offset=0" and get the info am after but the IPC would be nice Edited September 1, 2024 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Solution ioa747 Posted September 1, 2024 Solution Posted September 1, 2024 (edited) with the help of AI (I also put my hand in) Anyway, it's a start expandcollapse popup; https://www.autoitscript.com/forum/topic/212232-voidtools-everything-ipc #AutoIt3Wrapper_Res_Fileversion=0.0.0.3 #include <Date.au3> #include <Array.au3> Local $Result = _Everything(@ScriptDir) ; * <<-- _ArrayDisplay($Result) ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: _Everything ; Description....: Searches for files using the Everything SDK. ; Syntax.........: _Everything($sSearch) ; Parameters.....: $sSearch - The search query to use. ; Return values..: An array containing the results of the search, with each element being a 3-element array containing the following information: ; | 0 - The full path name of the file. ; | 1 - The date modified of the file in ISO format (yyyy-mm-dd hh:mm:ss). ; | 2 - The size of the file in bytes. ; Notes .........: This function uses the Everything SDK to search for files on the local machine. It is based on the Python example provided by Void Tools. ; https://www.voidtools.com/support/everything/sdk/python/ ; Link ..........: https://www.voidtools.com/support/everything/sdk/ipc/ ; Dependencies...: The Everything SDK must be installed and available in the same directory as this script. ;-------------------------------------------------------------------------------------------------------------------------------- Func _Everything($sSearch) ; Load the Everything DLL Local $EverythingDLL = DllOpen(@ScriptDir & "\Everything-SDK\dll\Everything32.dll") If $EverythingDLL = -1 Then MsgBox(16, "Error", "Failed to load Everything32.dll. Check the path and try again.") Exit EndIf ; Constants for the Everything Request Flags Local Const $EVERYTHING_REQUEST_FILE_NAME = 0x00000001 Local Const $EVERYTHING_REQUEST_PATH = 0x00000002 Local Const $EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004 Local Const $EVERYTHING_REQUEST_EXTENSION = 0x00000008 Local Const $EVERYTHING_REQUEST_SIZE = 0x00000010 Local Const $EVERYTHING_REQUEST_DATE_CREATED = 0x00000020 Local Const $EVERYTHING_REQUEST_DATE_MODIFIED = 0x00000040 Local $iFlags = BitOR($EVERYTHING_REQUEST_FILE_NAME, $EVERYTHING_REQUEST_PATH, $EVERYTHING_REQUEST_SIZE, $EVERYTHING_REQUEST_DATE_MODIFIED) ConsoleWrite("$iFlags=" & $iFlags & @CRLF) ; Set up search DllCall($EverythingDLL, "none", "Everything_SetSearchW", "wstr", $sSearch) ; Set request flags DllCall($EverythingDLL, "none", "Everything_SetRequestFlags", "dword", $iFlags) ; Execute the query DllCall($EverythingDLL, "int", "Everything_QueryW", "int", 1) ; Get the number of results Local $aResCnt = DllCall($EverythingDLL, "int", "Everything_GetNumResults") Local $iNumResults = $aResCnt[0] ;ConsoleWrite("Result Count: " & $iNumResults & @CRLF) Local $aResult[$iNumResults + 1][3] $aResult[0][0] = $iNumResults $aResult[0][1] = "Date Modified" $aResult[0][2] = "bytes" ; Create buffers Local $tFilename = DllStructCreate("wchar[260]") Local $tDateModified = DllStructCreate("uint LowPart; uint HighPart") Local $tFileSize = DllStructCreate("uint64") ; Show results For $i = 0 To $iNumResults - 1 ; Get result full path name DllCall($EverythingDLL, "none", "Everything_GetResultFullPathNameW", "int", $i, "ptr", DllStructGetPtr($tFilename), "int", 260) ; Get result date modified DllCall($EverythingDLL, "int", "Everything_GetResultDateModified", "int", $i, "ptr", DllStructGetPtr($tDateModified)) ; Get result size DllCall($EverythingDLL, "int", "Everything_GetResultSize", "int", $i, "ptr", DllStructGetPtr($tFileSize)) ; constructs the result $aResult[$i + 1][0] = DllStructGetData($tFilename, 1) $aResult[$i + 1][1] = _Date_Time_FileTimeToStr($tDateModified, 1) $aResult[$i + 1][2] = DllStructGetData($tFileSize, 1) Next ; Close the DLL DllClose($EverythingDLL) Return $aResult EndFunc ;==>_Everything ;-------------------------------------------------------------------------------------------------------------------------------- Func _HumanBytes($iBytes) Local $units_array[5] = ["bytes", "KB", "MB", "GB", "TB"] For $i = 0 To UBound($units_array) - 1 Step 1 If $iBytes < 1024 Then ExitLoop $iBytes /= 1024 Next Return $i = 0 ? StringFormat("%i %s", $iBytes, $units_array[$i]) : StringFormat("%.2f %s", $iBytes, $units_array[$i]) EndFunc ;==>_HumanBytes Edited September 5, 2024 by ioa747 correction Hadin and argumentum 2 I know that I know nothing
ioa747 Posted September 2, 2024 Posted September 2, 2024 (edited) packing a little I removed unused consts and put them inside the function for easier portability Edited September 2, 2024 by ioa747 argumentum 1 I know that I know nothing
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now