Sign in to follow this  
Followers 0
waardd

count number of specific windows

13 posts in this topic

I have a function that can count instances of putty.exe

Func _puttyteller();check aantal puttys
$list = ProcessList()
$puttycount = 0
;_ArrayDisplay($list)
For $i = 1 To $list[0][0]
If $list[$i][0] = "putty.exe" Then
  $puttycount = $puttycount + 1
EndIf
Next
GuiCtrlSetData($Inputputtycount, $puttycount)
;MsgBox(0, "", $x)
EndFunc

But what i really want is a function that counts the various instances of putty connected to different servers.

For example.

If there are 4 connections to servers with putty (2x serverA, 1x serverB and 1x serverC) my function counts 4 times putty.

What i am looking for is a function that gives me:

ServerA 2

ServerB 1

ServerC 1

Share this post


Link to post
Share on other sites



I want to count the windows that are running a putty session. To count the processes i already have a function.

Each putty session (putty.exe proces) can have a different connection and therefor a different window title. Example:

window title 1: lsrv1200 as waardd

window title 2: spinner as waardd

window title 3: spinner as waard

window title 4: lsrv1300 as waard

what i want is a list of connections like:

connected to spinner 2 times

connected to lsrv1200 1 time

connected to lsrv1300 1 time

But remember te window title varies a lot!!

Share this post


Link to post
Share on other sites

Well it would depend how much the window titles vary.

window title 1: lsrv1200 as waardd

window title 2: spinner as waardd

window title 3: spinner as waard

window title 4: lsrv1300 as waard

Can you give an example of how "window title 2" might vary?

is it something like "putty xyz", "putty ryu", etc...?


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Here are some title examples of putty sessions

bobtail as waardd /home/tab_unix/waardd

ridgeback as waardd /home/tab_unix/waardd

lsrv4172 as waarddd /home/waarddd

lsrv1173 as waarddd /home/waarddd

lsrv1173 as gkkp /appl/gkk/prod

tuatara

snuitmot

waarddd@lsrv1200:~

So you see there are lots of options ;)

Share this post


Link to post
Share on other sites

Nope sorry ;)

Any other idea's ??

>>>> Window <<<<

Title: ridgeback as waardd /home/tab_unix/waardd

Class: PuTTY

Position: 175, 175

Size: 675, 424

Style: 0x14EF0000

ExStyle: 0x00000100

Handle: 0x00260C18

>>>> Control <<<<

Class:

Instance:

ClassnameNN:

Name:

Advanced (Class):

ID:

Text:

Position:

Size:

ControlClick Coords:

Style:

ExStyle:

Handle:

>>>> Mouse <<<<

Position: 257, 82

Cursor ID: 0

Color: 0x000000

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

Share this post


Link to post
Share on other sites

That depends.

Sometimes its just a servername in the Title and sometimes the complete info like lsrv4172 as waarddd /home/waarddd in the title as mentioned before. The examples where all from the title bar. I can winlist() to put all processes in an array but i can't search on a partial string in the array.

Share this post


Link to post
Share on other sites

#11 ·  Posted

That depends.

Sometimes its just a servername in the Title and sometimes the complete info like lsrv4172 as waarddd /home/waarddd in the title as mentioned before. The examples where all from the title bar. I can winlist() to put all processes in an array but i can't search on a partial string in the array.

Why can't you search for a particular string in the array? _ArraySearch doesn't return anything?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Arraysearch returns the rowvalue for a partial string, however as said in earlier posts, this is a very variiable string.

What im looking for (i think) is this.

  • put processes in a list with winlist()
  • search the putty sessions with a routine that links PID to HWND
  • put the result in a new array
  • process the new array

Share this post


Link to post
Share on other sites

EUREKA!!! I got it working.

With help from a routine by

bobsyuruncle

I coded it like this:

#include <Array.au3>
Global $maxlines, $Wlist, $hwnd
$Wlist = winlist()
$Plist = ProcessList("putty.exe")

;_ArrayDisplay($Wlist,"Wlist")
;_ArrayDisplay($Plist,"Processlist")
$maxlinesW = $Wlist[0][0]
$maxlinesP = $Plist[0][0]
ConsoleWrite("WinlistAantal "&$maxlinesW&@CRLF)
ConsoleWrite("PlistAantal "&$maxlinesP&@CRLF)
Global $puttyarray[1]
_ArrayDisplay($puttyarray)
For $j = 1 to $maxlinesP
$hwnd = _GetHwndFromPID($Plist[$j][1])
ConsoleWrite("Gevonden PID's> "&$Plist[$j][0]&" "&$Plist[$j][1]&" met hwnd "&$HWND&@CRLF&@CRLF)
For $i = 1 to $maxlinesW
  if $Wlist[$i][1] = $hwnd then
  Consolewrite($Wlist[$i][0]&" "&$Wlist[$i][1]&@CRLF)
  $arrayline = $Wlist[$i][0]&" "&$Wlist[$i][1]
  _arrayadd($puttyarray, $arrayline)
  EndIf
Next

Next
_ArrayDelete($puttyarray, 0)
_ArrayDisplay($puttyarray)
Func _GetHwndFromPID($PID); Tnx for this routine bobsyuruncle
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc ;==>_GetHwndFromPID

Share this post


Link to post
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
Sign in to follow this  
Followers 0