This has already been posted here, i think by freak.
Anyway, here is a sample on how to get the process path from a window handle.
(Note: It won't run on 9x/Me, because they do not have the psapi.dll library)
Update: Read again your post and i think, this can do the job.
Code: Select all
Declare.s ProcessNameFromHwnd(hwnd)
Declare CheckWindowsProcess(WndHwnd, p)
Global USB_ROOT.s = "F:\" ; the root of your USB stick
; assuming that all applications started on your USB stick have a window, we could enumerate all windows
; and send a #wm_close message to the ones that have started on your USB stick.
Procedure CheckWindowsProcess(WndHwnd, p)
; check if the first third caracters of the process path are the USB_ROOT.s
Protected ProcessPath.s = ProcessNameFromHwnd(WndHwnd)
Protected Caption.s = Space(255)
If UCase(Mid(ProcessPath, 1, 3)) = UCase(USB_ROOT)
GetWindowText_(WndHwnd, @Caption, 255)
Debug "Title: " + Caption
Debug "Path: " + ProcessPath
Debug "Hwnd: " + Str(WndHwnd)
Debug "---------------------------"
; here, as you already have the Window Handle, you could send the #wm_close message
EndIf
ProcedureReturn #True ; return 1 to continue the enumeration
EndProcedure
Procedure.s ProcessNameFromHwnd(hwnd)
Protected ProcessID
Protected hProcess
Protected hModule
Protected ProcessName.s = Space(#MAX_PATH)
Protected EnumProcessModules
Protected GetModuleFileNameEx
If OpenLibrary(0, "psapi.dll")
EnumProcessModules = GetFunction(0, "EnumProcessModules")
GetModuleFileNameEx = GetFunction(0, "GetModuleFileNameExA")
GetWindowThreadProcessId_(hwnd, @ProcessID)
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION|#PROCESS_VM_READ, 0, ProcessID)
CallFunctionFast(EnumProcessModules, hProcess, @hModule, 1, 0)
CallFunctionFast(GetModuleFileNameEx, hProcess, hModule, @ProcessName, #MAX_PATH)
CloseHandle_(hProcess)
CloseLibrary(0)
EndIf
ProcedureReturn ProcessName
EndProcedure
Debug "applications started on " + USB_ROOT
Debug "------------------------------------"
EnumWindows_(@CheckWindowsProcess(), 1)
Debug "------------------------------------"
Debug "end"
Hope this helps.