Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM WinList.bat
- REM This file compiles WinList.vb to WinList.exe
- REM WinList.exe list the open windows and their child windows' Window Title, Window Class, and the EXE file that created the window
- REM To use type WinList in a command prompt
- C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\WinList.vb" /out:"%~dp0\WinList.exe" /target:exe
- Pause
- REM Sample Output
- REM -------------
- REM
- -----------------------------------------------------------------------------------------
- Window Text Class Name HWnd ParentHWnd ProcessID ThreadID Process
- Name
- «No Window Text 0» Shell_TrayWnd 65770 4588428 4152 4256 explorer.exe
- Start Start 65774 65770 4152 4256 explorer.exe
- «No Window Text 0» TrayDummySearchControl 65778 65770 4152 4256 explorer.exe
- Search Windows Button 65782 65778 4152 4256 explorer.exe
- «No Window Text 0» Edit 65780 65778 4152 4256 explorer.exe
- «No Window Text 0» ToolbarWindow32 65784 65778 4152 4256 explorer.exe
- Task View TrayButton 65786 65770 4152 4256 explorer.exe
- «No Window Text 0» TrayNotifyWnd 65790 65770 4152 4256 explorer.exe
- 3:37 PM TrayClockWClass 65792 65790 4152 4256 explorer.exe
- «No Window Text 0» TrayShowDesktopButtonWClass 65794 65790 4152 4256 explorer.exe
- Tray Input Indicator TrayInputIndicatorWClass 65796 65790 4152 4256 explorer.exe
- «No Window Text 0» Button 65798 65796 4152 4256 explorer.exe
- «No Window Text 0» Button 65802 65796 4152 4256 explorer.exe
- «No Window Text 0» SysPager 65806 65790 4152 4256 explorer.exe
- User Promoted Notification Area ToolbarWindow32 65818 65806 4152 4256 explorer.exe
- «No Window Text 0» Button 65812 65790 4152 4256 explorer.exe
- «No Window Text 0» Button 65814 65812 4152 4256 explorer.exe
- System Promoted Notification Area ToolbarWindow32 65820 65790 4152 4256 explorer.exe
- Notification Center TrayButton 458788 65790 4152 4256 explorer.exe
- Touch keyboard TIPBand 2097298 65790 4152 4256 explorer.exe
- «No Window Text 0» ReBarWindow32 65828 65770 4152 4256 explorer.exe
- Running applications MSTaskSwWClass 65830 65828 4152 4256 explorer.exe
- Running applications MSTaskListWClass 65832 65830 4152 4256 explorer.exe
- Favorites ToolbarWindow32 65838 65828 4152 4256 explorer.exe
- Desktop ToolbarWindow32 65844 65828 4152 4256 explorer.exe
- «No Window Text 0» tooltips_class32 65824 4588428 4152 4256 explorer.exe
- «No Window Text 0» NotifyIconOverflowWindow 65808 4588428 4152 4256 explorer.exe
- Overflow Notification Area ToolbarWindow32 65810 65808 4152 4256 explorer.exe
- «No Window Text 0» TaskListThumbnailWnd 65836 4588428 4152 4256 explorer.exe
- Default IME IME 66048 4588428 4152 4976 explorer.exe
- «No Window Text 0» ATL:00007FF9BFC77080 66046 4588428 4152 4976 explorer.exe
- Battery Meter SystemTray_Main 66028 4588428 4152 4856 explorer.exe
- Network Flyout ATL:00007FF9BBB23120 131146 4588428 4152 4976 explorer.exe
- «No Window Text 0» PNIHiddenWnd 131142 4588428 4152 4976 explorer.exe
- MSCTFIME UI MSCTFIME UI 14944004 4588428 7860 7720 conhost.exe
- Default IME IME 31065762 4588428 7860 7720 conhost.exe
- Administrator: Windows Command Processor - "C:\Users\User\Desktop\Bat&Vbs\WinList\WinList.exe" ConsoleWindowCla
- ss 29361348 4588428 2104 788 cmd.exe
- ---------------------------------------------------------------
- 'WinList.vb
- imports System.Runtime.InteropServices
- Public Module WinList
- Public Declare Function GetTopWindow Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
- Public Declare Function GetWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal wCmd As Integer) As IntPtr
- Public Declare UNICODE Function GetWindowModuleFileNameW Lib "user32" (ByVal hwnd As IntPtr, ByVal WinModule As String, StringLength As Integer) As Integer
- Public Declare UNICODE Function GetWindowTextW Lib "user32" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer
- Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr
- Public Declare UNICODE Function GetClassNameW Lib "user32" (ByVal hwnd As IntPtr, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
- Public Const GW_CHILD = 5
- Public Const GW_HWNDNEXT = 2
- Public Sub Main ()
- Dim WindowChain as Integer
- WindowChain = 0
- Dim hwnd As IntPtr
- hwnd = GetTopWindow(0)
- If hwnd <> 0 Then
- AddChildWindows(hwnd, 0)
- End If
- End Sub
- Private Sub AddChildWindows(ByVal hwndParent As IntPtr, ByVal Level As Integer)
- Dim objWMIService As Object
- Dim colItems As Object
- Dim TempStr As String
- Dim WT As String, CN As String, Length As Integer, hwnd As IntPtr, TID As IntPtr, PID As IntPtr, MN As String, Parenthwnd As IntPtr
- Static Order As Integer
- Static FirstTime As Integer
- Parenthwnd = hwndParent
- If Level = 0 Then
- hwnd = hwndParent
- Else
- hwnd = GetWindow(hwndParent, GW_CHILD)
- End If
- Do While hwnd <> 0
- WT = Space(512)
- Length = GetWindowTextW(hwnd, WT, 508)
- WT = Left$(WT, Length)
- If WT = "" Then WT = Chr(171) & "No Window Text " & Err.LastDllError & Chr(187)
- CN = Space(512)
- Length = GetClassNameW(hwnd, CN, 508)
- CN = Left$(CN, Length)
- If CN = "" Then CN = "Error=" & Err.LastDllError
- MN = ""
- TID = GetWindowThreadProcessId(hwnd, PID)
- objWMIService = GetObject("winmgmts:\\.\root\cimv2")
- colItems = objWMIService.ExecQuery("Select * From Win32_Process where ProcessID=" & CStr(PID))
- For Each objItem in colItems
- MN = objItem.name
- Next
- Order = Order + 1
- If FirstTime = 0 Then
- Console.writeline("Window Text " & vbTab & "Class Name " & vbTab & "HWnd" & vbTab & "ParentHWnd" & vbTab & "ProcessID" & vbTab & "ThreadID" & vbTab & "Process Name" )
- FirstTime = 1
- End If
- TempStr = vbCrLf & Space(Level * 3) & WT
- If 30 - len(TempStr) > -1 then
- TempStr = TempStr & space(30 - len(TempStr))
- End If
- TempStr = TempStr & vbTab & CN
- If 55 - len(TempStr) > -1 then
- TempStr = TempStr & space(55 - len(TempStr))
- End If
- Console.write(TempStr & vbTab & CStr(hwnd) & vbTab & CStr(Parenthwnd) & vbTab & CStr(PID) & vbTab & CStr(TID) & vbTab & MN )
- AddChildWindows(hwnd, Level + 1)
- hwnd = GetWindow(hwnd, GW_HWNDNEXT)
- Loop
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement