Code:
'**************************************
'   "OpenFiles.bas"

[B][SIZE="3"][COLOR="Red"]'Open-Files Lister 
with Snapshot Compare Feature[/COLOR]

'Notes:[/SIZE][/B]

[COLOR="Blue"]' Typical usage for finding out which files a program uses:
'1) Press "Refresh" to fill the "All" textbox with all files which
'	are currently open.
'2) Open the program of interest, allowing it to load completely.
'3) Press "Compare" to fill the "New" textbox with newly loaded files.

'*	"Refresh" always lists every file open at the time it's pressed.
'*	"Compare" gets a list of all open files from Windows then lists
'	only the ones which don't appear in the previously made main list.
'	In other words, it doesn't show which files in the main list have
'	been closed since the last "Refresh".[/COLOR]



[COLOR="Olive"][B]'		Ideas for Improvement:[/B]

'*	Cummulative listing with de-duplication to keep track of all files 
'	ever opened
'*	Show which files were closed for compares
'*	Compare any list with any other list, including any provided by 
'	the user.
'*	Filter by location, file type, time stamps and other properties.
'*	Show which processes have which files open programatically (without 
'	requiring the above "Compare" method)[/COLOR]


'Public domain by TheirCorp
'**************************************

#Compile Exe "OpenFiles.exe"
#Dim All



'**************************************
'this is an InClean file included inline
'**************************************
' Created by inClean v1.25, 09-28-2007, 11:55:30
' Press Help-button for some useful information and tips.
'
'  24282 lines of include file data read and compared against
'    279 lines of code in 0.88 seconds.
'
'-----------------------------------------------------------------
' Equates:  41
'-----------------------------------------------------------------

%WINAPI						= 1
%Null						= 0
%Normal						= &B000000
%Hidden						= &B000010
%System						= &B000100
%SubDir						= &B010000
%INVALID_HANDLE_VALUE		= &HFFFFFFFF???
%FILE_FLAG_DELETE_ON_CLOSE  = &H004000000
%VWIN32_DIOC_DOS_IOCTL		= 1 ' DOS IOCTL commands
%MAX_PATH					= 260 ' max. length of full pathname
%WM_NCACTIVATE				= &H86
%WM_INITDIALOG				= &H110
%WM_COMMAND					= &H111
%WS_POPUP					= &H80000000
%WS_CHILD					= &H40000000
%WS_VISIBLE					= &H10000000
%WS_CLIPSIBLINGS			= &H04000000
%WS_CAPTION					= &H00C00000 ' WS_BORDER OR WS_DLGFRAME
%WS_BORDER					= &H00800000
%WS_DLGFRAME				= &H00400000
%WS_VSCROLL					= &H00200000
%WS_HSCROLL					= &H00100000
%WS_SYSMENU					= &H00080000
%WS_TABSTOP					= &H00010000
%WS_MINIMIZEBOX				= &H00020000
%WS_EX_CLIENTEDGE			= &H00000200
%WS_EX_LEFT					= &H00000000
%WS_EX_LTRREADING			= &H00000000
%WS_EX_RIGHTSCROLLBAR		= &H00000000
%WS_EX_CONTROLPARENT		= &H00010000
%HWND_DESKTOP				= 0
%ES_LEFT					= &H0&
%ES_MULTILINE				= &H4&
%ES_AUTOHSCROLL				= &H80&
%ES_WANTRETURN				= &H1000&
%BN_CLICKED					= 0
%DS_3DLOOK					= &H0004&
%DS_NOFAILCREATE			= &H0010&
%DS_SETFONT					= &H0040& ' User specified font for Dlg controls
%DS_MODALFRAME				= &H0080& ' Can be combined with WS_CAPTION
%DS_CENTER					= &H0800&

'-----------------------------------------------------------------
' TYPE and UNION structures:  6
'-----------------------------------------------------------------
Type OVERLAPPED
	Internal As Dword
	InternalHigh As Dword
	offset As Dword
	OffsetHigh As Dword
	hEvent As Dword
End Type

Type SECURITY_ATTRIBUTES
	nLength As Dword
	lpSecurityDescriptor As Long
	bInheritHandle As Long
End Type

Type FILETIME
	dwLowDateTime As Dword
	dwHighDateTime As Dword
End Type

Type BY_HANDLE_FILE_INFORMATION
	dwFileAttributes As Dword
	ftCreationTime As FILETIME
	ftLastAccessTime As FILETIME
	ftLastWriteTime As FILETIME
	dwVolumeSerialNumber As Dword
	nFileSizeHigh As Dword
	nFileSizeLow As Dword
	nNumberOfLinks As Dword
	nFileIndexHigh As Dword
	nFileIndexLow As Dword
End Type

Type DIOC_REGISTERS
	regEBX As Dword
	regEDX As Dword
	regECX As Dword
	regEAX As Dword
	regEDI As Dword
	regESI As Dword
	regFlags As Dword
End Type

Type WIN32_FIND_DATA
	dwFileAttributes As Dword
	ftCreationTime As FILETIME
	ftLastAccessTime As FILETIME
	ftLastWriteTime As FILETIME
	nFileSizeHigh As Dword
	nFileSizeLow As Dword
	dwReserved0 As Dword
	dwReserved1 As Dword
	cFileName As Asciiz * %MAX_PATH
	cAlternateFileName As Asciiz * 14
End Type

'-----------------------------------------------------------------
' Declared Functions:  7
'-----------------------------------------------------------------
Declare Function CreateFile Lib "KERNEL32.DLL" Alias "CreateFileA" (lpFileName As Asciiz, ByVal dwDesiredAccess As Dword, ByVal dwShareMode As Dword, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Dword, _
	ByVal dwFlagsAndAttributes As Dword, ByVal hTemplateFile As Dword) As Dword
Declare Function DeviceIoControl Lib "KERNEL32.DLL" Alias "DeviceIoControl" (ByVal hDevice As Dword, ByVal dwIoControlCode As Dword, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, _
	lpBytesReturned As Long, lpOverlapped As OVERLAPPED) As Long
Declare Function FindClose Lib "KERNEL32.DLL" Alias "FindClose" (ByVal hFindFile As Dword) As Long
Declare Function FindFirstFile Lib "KERNEL32.DLL" Alias "FindFirstFileA" (lpFileName As Asciiz, lpFindFileData As WIN32_FIND_DATA) As Dword
Declare Function GetFocus Lib "USER32.DLL" Alias "GetFocus" () As Dword
Declare Function GetLogicalDrives Lib "KERNEL32.DLL" Alias "GetLogicalDrives" () As Long
Declare Function SetFocus Lib "USER32.DLL" Alias "SetFocus" (ByVal hWnd As Dword) As Long

'**************************************
'	end if InClean file
'**************************************



%Dlg	 =  101
%RefBtn  = 1001
%CompBtn = 1002
%AllLbl  = 1003
%AllTxt  = 1004
%NewLbl  = 1005
%NewTxt  = 1006

$Caption	= "Open File Lister"

Global ghDlg	As Dword

'**************************************

Sub CompareList(ps1() As String, ps2() As String)
Local i			As Long
Local fExist	As Long

	Do Until i = UBound(ps1)

		If Len(ps1(i)) Then

			Array Scan ps2(), Collate UCase, = ps1(i), To fExist
			If fExist Then
				Array Delete ps1(i)
				Iterate Do
			End If

		End If

		Incr i

	Loop

	Array Scan ps1(), = "", To i
	If i Then ReDim Preserve ps1(i - 1)

End Sub 'CompareList

'**************************************
'returns the total of all file sizes
'this assumes that not even the total of the 
'file sizes will over flow a Quad variable
Function FileSizes(ps() As String, sz() As Dword) As Quad
Local i			As Long
Local qt		As Long 'total of file sizes

Local hFind		As Dword
Local wfd		As WIN32_FIND_DATA

	ReDim sz(UBound(ps))

	For i = 0 To UBound(ps)

		If Len(ps(i)) And Len(Dir$(ps(i))) Then

			hFind = FindFirstFile(ByVal StrPtr(ps(i)), wfd)
			If hFind <> %INVALID_HANDLE_VALUE Then
				sz(i) = wfd.nFileSizeLow
				qt = qt + sz(i)
				FindClose(hFind)
			End If

		End If

	Next i

	Function = qt

End Function 'FileSizes

'**************************************
'This only corrects the capitalization of the portions it expands.
'returns the change in length of original string
' A value of -1 indicates an error
'this should check for the system's character for
'converting long file names to short ones
Function MakeLongPathName(ps As String) As Long
Local a		As Long
Local n		As Long
Local p1	As Long
Local p2	As Long
Local ls	As String

	ps = Trim$(ps, Any $Nul & $Spc)
	a = Len(ps)

	Do
		n = InStr(n + 1, ps, "~")

		If n Then

			p1 = InStr(n - Len(ps), ps, "\")
			p2 = InStr(n, ps, "\") : p2 = IIf&(p2, p2, Len(ps) + 1)
			ls = Dir$(Left$(ps, p2 - 1), %NORMAL Or %HIDDEN Or %SYSTEM Or %SUBDIR)

			If Len(ls) Then
				ps = Left$(ps, p1) & ls & Mid$(ps, p2)
			Else
				Function = -1
				Exit Function
			End If

		End If

	Loop While n

	Function = Len(ps) - a

End Function 'MakeLongPathName

'**************************************
'returns count of open files
Function GetOpenFiles(ps() As String) As Long
Local ct	As Long 'file count
Local n		As Long
Local p		As Dword
Local d		As Long

Local dn	As Long
Local hf	As Long
Local ls	As String
Local ts	As String
Local dr	As DIOC_REGISTERS
Local bhfi  As BY_HANDLE_FILE_INFORMATION

	p = GetLogicalDrives()
	Do
		If p Then Incr dn
		Shift Right p, 1
	Loop While p
	If dn < 3 Then Exit Function

	For dn = 3 To dn

		n = 0

		hf = CreateFile("\\.\vwin32", 0, 0, ByVal %Null, 0, %FILE_FLAG_DELETE_ON_CLOSE, %Null)
		Do
			ls = String$(%MAX_PATH, $Nul)
			dr.regEBX	 = dn  '1-based drive number
			dr.regEDX	 = StrPtr(ls)
			dr.regECX	 = &H0486D
			dr.regEAX	 = &H0440D
			dr.regESI	 = n

			Call DeviceIoControl(hf, %VWIN32_DIOC_DOS_IOCTL, dr, SizeOf(dr), dr, SizeOf(dr), d, ByVal %Null)

			If (dr.regFlags And 1) Then Exit Do

			MakeLongPathName(ls)

			'avoid duplicates and keep only the most recently retreived occurrences
			ls = ls & $CrLf
			If InStr(ts, ls) Then ts = Remove$(ts, ls) Else Incr ct
			ts = ts & ls

			Incr n

		Loop

	Next dn

	Function = ct 'return count of open files
	ReDim Preserve ps(ParseCount(ts, $CrLf))
	Parse ts, ps(), $CrLf

End Function 'GetOpenFiles

'**************************************

CallBack Function ShowProc()
Static AllFiles()	As String
Static NewFiles()	As String
Static sz()			As Dword 'sizes of files in NewFiles()
Local  qt			As Quad  'total of file sizes
Local i				As Long
Local n				As Long
Local ls			As String

	Select Case As Long CbMsg
		Case %WM_INITDIALOG
			Dim NewFiles(0)
			Dim AllFiles(0)
			Dim sz(0)

		Case %WM_NCACTIVATE
			Static hWndSaveFocus As Dword
			If IsFalse CbWParam Then
				hWndSaveFocus = GetFocus()
			ElseIf hWndSaveFocus Then
				SetFocus(hWndSaveFocus)
				hWndSaveFocus = 0
			End If

		Case %WM_COMMAND

			Select Case As Long CbCtl

				Case %RefBtn
					If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
						n = GetOpenFiles(AllFiles())
						ls = "Open files: " & Format$(n) & $CrLf & $CrLf & Join$(AllFiles(), $CrLf)
						Control Set Text ghDlg, %AllTxt, ls
					End If

				Case %CompBtn
					If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
						GetOpenFiles(NewFiles())
						CompareList(NewFiles(), AllFiles())
						qt = FileSizes(NewFiles(), sz())

						For i = 0 To UBound(NewFiles)
							If Len(NewFiles(i)) Then
								Incr n 'get file count
								ls = ls & NewFiles(i) & Space$(8) & Format$(sz(i), "0,") & $CrLf
							End If
						Next i

						'prepend these in the reverse order that they'll appear
						ls = "Total bytes: " & Format$(qt, "0,") & $CrLf & $CrLf & ls
						ls = "New files: " & Format$(n, "0,") & $CrLf & ls
						Control Set Text ghDlg, %NewTxt, ls

					End If

				Case 2 'cancel
					Dialog End ghDlg

			End Select

	End Select

End Function

'**************************************

Function PBMain()
Local lRslt As Long

	Dialog New %HWND_DESKTOP, $Caption, 218, 61, 321, 229, %WS_POPUP Or %WS_BORDER Or _
		%WS_DLGFRAME Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CLIPSIBLINGS Or _
		%WS_VISIBLE Or %DS_MODALFRAME Or %DS_CENTER Or %DS_3DLOOK Or %DS_NOFAILCREATE Or _
		%DS_SETFONT, %WS_EX_CONTROLPARENT Or %WS_EX_LEFT Or %WS_EX_LTRREADING Or _
		%WS_EX_RIGHTSCROLLBAR, To ghDlg
	Control Add Button,  ghDlg, %RefBtn, "&Refresh", 274, 10, 40, 14
	Control Add Button,  ghDlg, %CompBtn, "&Compare", 274, 128, 40, 14
	Control Add Label,   ghDlg, %AllLbl, "&All open files:", 2, 0, 265, 10
	Control Add TextBox, ghDlg, %AllTxt, "", 2, 11, 265, 97, %WS_CHILD Or %WS_VISIBLE Or _
		%WS_TABSTOP Or %WS_HSCROLL Or %WS_VSCROLL Or %ES_LEFT Or %ES_MULTILINE Or _
		%ES_AUTOHSCROLL Or %ES_WANTRETURN, %WS_EX_CLIENTEDGE Or %WS_EX_LEFT Or %WS_EX_LTRREADING _
		Or %WS_EX_RIGHTSCROLLBAR
	Control Add Label,   ghDlg, %NewLbl, "&New open files and sizes in bytes:", 2, 118, 265, 10
	Control Add TextBox, ghDlg, %NewTxt, "", 2, 128, 265, 97, %WS_CHILD Or %WS_VISIBLE Or _
		%WS_TABSTOP Or %WS_HSCROLL Or %WS_VSCROLL Or %ES_LEFT Or %ES_MULTILINE Or _
		%ES_AUTOHSCROLL Or %ES_WANTRETURN, %WS_EX_CLIENTEDGE Or %WS_EX_LEFT Or %WS_EX_LTRREADING _
		Or %WS_EX_RIGHTSCROLLBAR

	Dialog Show Modal ghDlg, Call ShowProc To lRslt

	Function = lRslt

End Function

'**************************************

  • TheirCorp's SourceForge project
    includes:
  • API Helper --- a code generator for the Win32 API
  • BinEditPlus --- a decompiler and more
  • ComHelper --- a code generator for the COM programming
  • "Flex" --- an editor with novel features
  • GDI Debug --- catches programming errors that could lead
    to resource leaks
  • Import Monitor --- (an API hook) Intercepts and monitors
    calls to imported functions
  • Intricately Mergeable Templates
  • Jellyfish Pro enhancer plugin (adds drag-and-drop and more..)
  • TheirEdit --- an editor for PowerBASIC code
  • TheirNote --- a KeyNote clone
  • TheirSheet --- a spreadsheet
  • SrcFrmt --- a source code formatter
  • Tooltipper --- a tooltip code generator


PowerBASIC article in Wikipedia