Jump to content



Photo

count number of specific windows


  • Please log in to reply
12 replies to this topic

#1 waardd

waardd

    Seeker

  • Active Members
  • 36 posts

Posted 08 May 2012 - 12:15 PM

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





#2 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 08 May 2012 - 01:21 PM

So do you want to count the windows or the processes?

I'm not familiar with putty, but do the window titles indicate which server they are connected to?
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#3 waardd

waardd

    Seeker

  • Active Members
  • 36 posts

Posted 08 May 2012 - 01:26 PM

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!!

#4 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 08 May 2012 - 02:30 PM

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
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#5 waardd

waardd

    Seeker

  • Active Members
  • 36 posts

Posted 09 May 2012 - 05:31 AM

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 ;)

#6 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 09 May 2012 - 11:00 AM

I see.
How about text or hidden text in the window, or status bar perhaps?
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#7 waardd

waardd

    Seeker

  • Active Members
  • 36 posts

Posted 09 May 2012 - 11:59 AM

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 <<<<

#8 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 09 May 2012 - 12:09 PM

OK so you can get all the putty windows with the class name.

Are there any controls on the gui which indicate the server you are on, how do you
visibly know which one you are connected to?
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#9 waardd

waardd

    Seeker

  • Active Members
  • 36 posts

Posted 09 May 2012 - 12:46 PM

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.

#10 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 09 May 2012 - 01:15 PM

Well if there is absolutely no server info in the whole gui to tell you where you are connected you might be goosed.

What's this "plink" business could that help you?
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#11 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,828 posts

Posted 09 May 2012 - 01:23 PM

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?

How to ask questions the smart way!

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#12 waardd

waardd

    Seeker

  • Active Members
  • 36 posts

Posted 10 May 2012 - 08:28 AM

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


#13 waardd

waardd

    Seeker

  • Active Members
  • 36 posts

Posted 10 May 2012 - 09:32 AM

EUREKA!!! I got it working.

With help from a routine by
bobsyuruncle


I coded it like this:
Plain Text         
#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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users