Jump to content
Sign in to follow this  
bordomavi

I need help about winlist

Recommended Posts

bordomavi

Local $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
        MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
    EndIf
Next

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

EndFunc   ;==>IsVisible

I dont understand it. i want create list for example "window1", "window2", "window3"

and when winexist window one of list than processclose("blabla.exe")

Share this post


Link to post
Share on other sites
kylomas

bordomavi,

After you find the "window" that you want to close you need to find the process id using "wingetprocess".  You can then manipulate the process by process id.

The following code shows how to associate the window handle with a process id.

#include <array.au3>

;---------------------------------------------
;  define arrays
;---------------------------------------------

local $list[300][4]                                                 ; 300 windows max
local enum $title, $handle, $pid, $exe                              ; enumerations for array offsets

;---------------------------------------------
;  get array of windows and populate $list
;---------------------------------------------

local $a1 = winlist()                                               ; get list of windows

for $i = 0 to $a1[0][0]                                             ; and copy title, handle and pid to $list array
    $list[$i][$title]   = $a1[$i][$title]                           ; window title
    $list[$i][$handle]  = $a1[$i][$handle]                          ; window handle
    $list[$i][$pid]     = wingetprocess($a1[$i][$handle])           ; owning process id
next

;---------------------------------------------
;  get array of processes and populate $list
;---------------------------------------------

local $a2 = processlist()                                           ; get list of processes

for $i = 0 to $a1[0][0]
    for $j = 0 to $a2[0][0]
        if $list[$i][2] = $a2[$j][1] then $list[$i][3] = $a2[$j][0] ; and copy process name to $list array
    Next
next

_arraysort($list,1,0,0,2)                                           ; sort the array by pid

_arraydisplay($list)

;---------------------------------------------
;  format output to console
;---------------------------------------------

local $savepid = '', $out = ''

for $i = 0 to ubound($list) - 1
    if $i = 0 then
        $out &= stringformat('%-10s%-15s',$list[$i][$pid],$list[$i][$exe]) & @crlf
        $savepid = $list[$i][$pid]
    endif
    if $list[$i][$pid] = '' then exitloop
    if  $savepid = $list[$i][$pid] then
        if $list[$i][$title] <> '' then $out &= @tab & @tab & $list[$i][$title] & @crlf
    else
        if $i <> 0 then $out &= stringformat('%-10s%-15s',$list[$i][$pid],$list[$i][$exe]) & @crlf
        $savepid = $list[$i][$pid]
    endif
next

consolewrite($out & @lf)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
careca

Did something that does that, maybe you can check the code and see how it works.

'?do=embed' frameborder='0' data-embedContent>>


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
bordomavi

bordomavi,

After you find the "window" that you want to close you need to find the process id using "wingetprocess".  You can then manipulate the process by process id.

The following code shows how to associate the window handle with a process id.

#include <array.au3>

;---------------------------------------------
;  define arrays
;---------------------------------------------

local $list[300][4]                                                 ; 300 windows max
local enum $title, $handle, $pid, $exe                              ; enumerations for array offsets

;---------------------------------------------
;  get array of windows and populate $list
;---------------------------------------------

local $a1 = winlist()                                               ; get list of windows

for $i = 0 to $a1[0][0]                                             ; and copy title, handle and pid to $list array
    $list[$i][$title]   = $a1[$i][$title]                           ; window title
    $list[$i][$handle]  = $a1[$i][$handle]                          ; window handle
    $list[$i][$pid]     = wingetprocess($a1[$i][$handle])           ; owning process id
next

;---------------------------------------------
;  get array of processes and populate $list
;---------------------------------------------

local $a2 = processlist()                                           ; get list of processes

for $i = 0 to $a1[0][0]
    for $j = 0 to $a2[0][0]
        if $list[$i][2] = $a2[$j][1] then $list[$i][3] = $a2[$j][0] ; and copy process name to $list array
    Next
next

_arraysort($list,1,0,0,2)                                           ; sort the array by pid

_arraydisplay($list)

;---------------------------------------------
;  format output to console
;---------------------------------------------

local $savepid = '', $out = ''

for $i = 0 to ubound($list) - 1
    if $i = 0 then
        $out &= stringformat('%-10s%-15s',$list[$i][$pid],$list[$i][$exe]) & @crlf
        $savepid = $list[$i][$pid]
    endif
    if $list[$i][$pid] = '' then exitloop
    if  $savepid = $list[$i][$pid] then
        if $list[$i][$title] <> '' then $out &= @tab & @tab & $list[$i][$title] & @crlf
    else
        if $i <> 0 then $out &= stringformat('%-10s%-15s',$list[$i][$pid],$list[$i][$exe]) & @crlf
        $savepid = $list[$i][$pid]
    endif
next

consolewrite($out & @lf)

kylomas

where i write window title and processname?

Share this post


Link to post
Share on other sites
kylomas

bordomavi,

The code I posted is just a visual representation of how the process id related to the window(s).

After you find the "window" that you want to close you need to find the process id using "wingetprocess". You can then manipulate the process by process id.

 

So, using the code you posted it might look like this (untested)

Local $var = WinList(), $pid

For $i = 1 To $var[0][0]
    ; Only display visble windows that have a title
    If $var[$i][0] = "the title that I am looking for" And IsVisible($var[$i][1]) Then
            $pid = wingetprocess($var[$i][1])
            ;
            ; do something with it
            ;
    EndIf
Next

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

EndFunc   ;==>IsVisible

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
bordomavi

bordomavi,

The code I posted is just a visual representation of how the process id related to the window(s).

 

So, using the code you posted it might look like this (untested)

Local $var = WinList(), $pid

For $i = 1 To $var[0][0]
    ; Only display visble windows that have a title
    If $var[$i][0] = "the title that I am looking for" And IsVisible($var[$i][1]) Then
            $pid = wingetprocess($var[$i][1])
            ;
            ; do something with it
            ;
    EndIf
Next

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

EndFunc   ;==>IsVisible

kylomas

i dont want it. i want this:

for example:

"window1"   ;

"window2"   ;

"window3"   ; these are list

"window4"   ;

if winexist "any window from list" than

processclose("a.exe")

processclose("b.exe")

end if

Share this post


Link to post
Share on other sites
Chimp

hi bordomavi

excuse me,
but which windows should go in your list?


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
bordomavi

hi bordomavi

excuse me,

but which windows should go in your list?

any windows. i write manuel.

Share this post


Link to post
Share on other sites
Chimp

to identify a windows of your choice between many, you must decide how to chose it, one way is select a windows with a specific title in the middle of others, so your "list" should be a list of windows titles (the ones you want to check the existence).
if I haven't understand wrong, then this code should do

local $MyList[4] = ["window1","window2","window3","window4"] ; the list of yours window titles

for $i = 1 to UBound($MyList) -1
 ; check the existence of one window with one of your titles    
    if WinExists($MyList[$i]) Then ; if it finds
        ; do what you want
        ExitLoop ; do not search no more
    EndIf
next

no need of WinList


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
bordomavi

to identify a windows of your choice between many, you must decide how to chose it, one way is select a windows with a specific title in the middle of others, so your "list" should be a list of windows titles (the ones you want to check the existence).

if I haven't understand wrong, then this code should do

local $MyList[4] = ["window1","window2","window3","window4"] ; the list of yours window titles

for $i = 1 to UBound($MyList) -1
 ; check the existence of one window with one of your titles    
    if WinExists($MyList[$i]) Then ; if it finds
        ; do what you want
        ExitLoop ; do not search no more
    EndIf
next

no need of WinList

it choose 1 window or existing window ?

Share this post


Link to post
Share on other sites
Chimp

it looks for the existence of at least one of the windows of your list


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
bordomavi

it looks for the existence of at least one of the windows of your list

ok ty very much

Share this post


Link to post
Share on other sites
Chimp

You're Welcome


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
bordomavi

You're Welcome

hey 

local $MyList[4] = ["pencere1","pencere2","pencere3","pencere4"]
 
for $i = 1 to UBound($MyList) -1
   
    if ProcessExists($MyList[$i]) Then
        ProcessClose("abxde.exe")
        ProcessClose("blabla.exe") 
        ExitLoop
    EndIf
next

it is not working. is it possible like this ? with processexists and processclose

Share this post


Link to post
Share on other sites
Chimp

sorry, there is a little bug,
instead of
... for $i = 1 to ...
must be used this
... for $i = 0 to ...

the loop begins from 0 and not from 1 otherwise you loose the first item

also, if you use ProcessExists() , you must use the full name of the process
example:
"pencere1.exe","pencere2.exe","pencere3.exe","pencere4.exe"


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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  

×