Advertisement
dcandygmailcom

WinList.exe list the open windows and their child windows' W

Feb 13th, 2019
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.09 KB | None | 0 0
  1. REM WinList.bat
  2. REM This file compiles WinList.vb to WinList.exe
  3. REM WinList.exe list the open windows and their child windows' Window Title, Window Class, and the EXE file that created the window
  4. REM To use type WinList in a command prompt
  5. C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\WinList.vb" /out:"%~dp0\WinList.exe" /target:exe
  6. Pause
  7. REM Sample Output
  8. REM -------------
  9. REM
  10.  
  11. -----------------------------------------------------------------------------------------
  12.  
  13. Window Text                     Class Name                      HWnd    ParentHWnd      ProcessID   ThreadID    Process
  14. Name
  15. «No Window Text 0»              Shell_TrayWnd                   65770   4588428 4152    4256    explorer.exe
  16.    Start                        Start                           65774   65770   4152    4256    explorer.exe
  17.    «No Window Text 0»           TrayDummySearchControl          65778   65770   4152    4256    explorer.exe
  18.       Search Windows            Button                          65782   65778   4152    4256    explorer.exe
  19.       «No Window Text 0»        Edit                            65780   65778   4152    4256    explorer.exe
  20.       «No Window Text 0»        ToolbarWindow32                 65784   65778   4152    4256    explorer.exe
  21.    Task View                    TrayButton                      65786   65770   4152    4256    explorer.exe
  22.    «No Window Text 0»           TrayNotifyWnd                   65790   65770   4152    4256    explorer.exe
  23.       3:37 PM                   TrayClockWClass                 65792   65790   4152    4256    explorer.exe
  24.       «No Window Text 0»        TrayShowDesktopButtonWClass     65794   65790   4152    4256    explorer.exe
  25.       Tray Input Indicator      TrayInputIndicatorWClass        65796   65790   4152    4256    explorer.exe
  26.          «No Window Text 0»     Button                          65798   65796   4152    4256    explorer.exe
  27.          «No Window Text 0»     Button                          65802   65796   4152    4256    explorer.exe
  28.       «No Window Text 0»        SysPager                        65806   65790   4152    4256    explorer.exe
  29.          User Promoted Notification Area        ToolbarWindow32 65818   65806   4152    4256    explorer.exe
  30.       «No Window Text 0»        Button                          65812   65790   4152    4256    explorer.exe
  31.          «No Window Text 0»     Button                          65814   65812   4152    4256    explorer.exe
  32.       System Promoted Notification Area ToolbarWindow32 65820   65790   4152    4256    explorer.exe
  33.       Notification Center       TrayButton                      458788  65790   4152    4256    explorer.exe
  34.       Touch keyboard            TIPBand                         2097298 65790   4152    4256    explorer.exe
  35.    «No Window Text 0»           ReBarWindow32                   65828   65770   4152    4256    explorer.exe
  36.       Running applications      MSTaskSwWClass                  65830   65828   4152    4256    explorer.exe
  37.          Running applications   MSTaskListWClass        65832   65830   4152    4256    explorer.exe
  38.       Favorites                 ToolbarWindow32                 65838   65828   4152    4256    explorer.exe
  39.       Desktop                   ToolbarWindow32                 65844   65828   4152    4256    explorer.exe
  40. «No Window Text 0»              tooltips_class32                65824   4588428 4152    4256    explorer.exe
  41. «No Window Text 0»              NotifyIconOverflowWindow        65808   4588428 4152    4256    explorer.exe
  42.    Overflow Notification Area   ToolbarWindow32         65810   65808   4152    4256    explorer.exe
  43. «No Window Text 0»              TaskListThumbnailWnd            65836   4588428 4152    4256    explorer.exe
  44. Default IME                     IME                             66048   4588428 4152    4976    explorer.exe
  45. «No Window Text 0»              ATL:00007FF9BFC77080            66046   4588428 4152    4976    explorer.exe
  46. Battery Meter                   SystemTray_Main                 66028   4588428 4152    4856    explorer.exe
  47. Network Flyout                  ATL:00007FF9BBB23120            131146  4588428 4152    4976    explorer.exe
  48. «No Window Text 0»              PNIHiddenWnd                    131142  4588428 4152    4976    explorer.exe
  49. MSCTFIME UI                     MSCTFIME UI                     14944004        4588428 7860    7720    conhost.exe
  50. Default IME                     IME                             31065762        4588428 7860    7720    conhost.exe
  51. Administrator: Windows Command Processor - "C:\Users\User\Desktop\Bat&Vbs\WinList\WinList.exe"   ConsoleWindowCla
  52. ss      29361348        4588428 2104    788     cmd.exe
  53. ---------------------------------------------------------------
  54.  
  55. 'WinList.vb
  56. imports System.Runtime.InteropServices
  57. Public Module WinList  
  58.  
  59. Public Declare Function GetTopWindow Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
  60. Public Declare Function GetWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal wCmd As Integer) As IntPtr
  61. Public Declare UNICODE Function GetWindowModuleFileNameW Lib "user32" (ByVal hwnd As IntPtr, ByVal WinModule As String, StringLength As Integer) As Integer
  62. Public Declare UNICODE Function GetWindowTextW Lib "user32" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer
  63. Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr
  64. Public Declare UNICODE Function GetClassNameW Lib "user32" (ByVal hwnd As IntPtr, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
  65. Public Const GW_CHILD = 5
  66. Public Const GW_HWNDNEXT = 2
  67.        
  68. Public Sub Main ()
  69.     Dim WindowChain as Integer
  70.         WindowChain = 0
  71.     Dim hwnd As IntPtr
  72.     hwnd = GetTopWindow(0)
  73.     If hwnd <> 0 Then
  74.                     AddChildWindows(hwnd, 0)
  75.             End If
  76. End Sub
  77.  
  78.  
  79. Private Sub AddChildWindows(ByVal hwndParent As IntPtr, ByVal Level As Integer)
  80.     Dim objWMIService As Object
  81.     Dim colItems As Object
  82.     Dim TempStr As String  
  83.     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
  84.         Static Order As Integer
  85.         Static FirstTime As Integer
  86.         Parenthwnd = hwndParent
  87.         If Level = 0 Then
  88.                         hwnd = hwndParent
  89.         Else
  90.             hwnd = GetWindow(hwndParent, GW_CHILD)
  91.         End If
  92.         Do While hwnd <> 0
  93.                  WT = Space(512)
  94.                   Length = GetWindowTextW(hwnd, WT, 508)
  95.                   WT = Left$(WT, Length)
  96.                   If WT = "" Then WT = Chr(171) & "No Window Text " & Err.LastDllError & Chr(187)
  97.                   CN = Space(512)
  98.                   Length = GetClassNameW(hwnd, CN, 508)
  99.                   CN = Left$(CN, Length)
  100.                   If CN = "" Then CN = "Error=" & Err.LastDllError
  101.                   MN = ""
  102.                  
  103.                   TID = GetWindowThreadProcessId(hwnd, PID)
  104.                  
  105.     objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  106.     colItems = objWMIService.ExecQuery("Select * From Win32_Process where ProcessID=" & CStr(PID))
  107.     For Each objItem in colItems   
  108.         MN = objItem.name
  109.     Next                       
  110.                  
  111.                   Order = Order + 1
  112.                 If FirstTime = 0 Then
  113.                     Console.writeline("Window Text                   " & vbTab & "Class Name               " & vbTab & "HWnd" & vbTab & "ParentHWnd" & vbTab & "ProcessID" & vbTab & "ThreadID" & vbTab & "Process Name" )
  114.                     FirstTime = 1
  115.                 End If
  116.     TempStr = vbCrLf & Space(Level * 3) & WT
  117.     If 30 - len(TempStr) > -1 then
  118.         TempStr = TempStr & space(30 - len(TempStr))
  119.     End If
  120.     TempStr = TempStr & vbTab & CN
  121.     If 55 - len(TempStr) > -1 then
  122.         TempStr = TempStr & space(55 - len(TempStr))
  123.     End If
  124.                 Console.write(TempStr  & vbTab & CStr(hwnd) & vbTab & CStr(Parenthwnd) & vbTab & CStr(PID) & vbTab & CStr(TID) & vbTab & MN )
  125.                  
  126.                   AddChildWindows(hwnd, Level + 1)
  127.                   hwnd = GetWindow(hwnd, GW_HWNDNEXT)
  128.         Loop
  129.       End Sub
  130.  
  131. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement