Jump to content

List of program names like Window Alt Tab switcher


Recommended Posts

Hi, I have a need to automate some programs. To do so I need a list of the programs in the order accessed. What I need is a way to create a list and save it to a file (e.g. userPrograms.txt) in a folder. I would like to list them by the program name. I would like the list to be just like Windows (Alt + Tab) app switcher. I would like them to be in the same order accessed. I am working with Illustrator and Photoshop Word and Excel. I have been working with the functions WinList and FileWrite but cannot get exactly what I want. Also, I would like to know is there a way to get a list of the program exe (e.g. Photoshop.exe, WINWORD.exe) names and not the Window names or handle. The reason is that the window names for Adobe Illustrator and Photoshop can be very general and similar. Could somebody show me how to do this? If it cannot be to the letter of how I describe it is OK. If it is anything close it can be worked with. Thanks for any help

 

Example4AutoIt.jpg

Edited by pctechtv
Link to comment
Share on other sites

For a complete list of desktop windows in z order, I recommend using _WinAPI_EnumWindowsTop.  See help file for an example.  All you have to do is deselect the base windows to keep only applications.

Link to comment
Share on other sites

you got:

_WinAPI_GetParentProcess($iID)  

_WinAPI_GetProcessFileName($iID)

With what ever you choose to winlist  use the GetprocceName file name with StringInStr if that wont do try  GetParent first ,then GetProccename  to see if it will match 

lastly with a clean list set a new hotkey with a function to switch between the windows you got set

Edited by Deye
Link to comment
Share on other sites

Thank you all again for the great help on this forum. I have to say I am always impressed when I come here. I was able to get exactly what I want with the help I received. I will mention to any novice like myself pay attention to the dependencies the AutoIt functions need at the top of the code (e.g. “#include <WinAPIProc.au3>”). The example I post gave me more than what I needed in my text file; however, I post to be useful to other members. Thanks

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPISysWin.au3>
#include <WinAPIProc.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = "C:\PSUtil\AutoItTest.txt"
    Local $aList = WinList()

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf
    
    FileWrite($hFileOpen, "")

    ; Loop through the array displaying only visable windows with a title.
    For $i = 1 To $aList[0][0]
        If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
            ; Retrieve the handle of the Notepad window using the classname of Notepad.
            Local $hWnd = WinGetHandle($aList[$i][0])

            ; Retrieve the identifier of the thread and pass a variable to the $iPID parameter to store the PID.
            Local $iPID = 0
            Local $iThread = _WinAPI_GetWindowThreadProcessId($hWnd, $iPID)
            
            ; This is more than I needed for my text file... I just wanted the Processname... I post to be useful to others
            FileWrite($hFileOpen, ' Process thread:'  & $iThread & '  Process ID (PID): ' & $iPID & "  Processname:" & _WinAPI_GetProcessName($iPID) & "  filename:" & _WinAPI_GetProcessFileName($iPID) & @CRLF )
        EndIf
    Next

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

    
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Nice and well documented example.
Here are a few remarks to make the example executable for everyone.

1.) It is good practice to create the output file within the user folder. Not everyone has write access to the root directory.

2.) It is useful for the convenience of the user to display the result in an editor.

Local Const $sFilePath = @DesktopDir & "\PSUtil\AutoItTest.txt"

Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE + $FO_CREATEPATH)

ShellExecute($sFilePath)

Here my new code:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPISysWin.au3>
#include <WinAPIProc.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = @DesktopDir & "\PSUtil\AutoItTest.txt"
    Local $aList = WinList()

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE + $FO_CREATEPATH)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf

    FileWrite($hFileOpen, "")

    ; Loop through the array displaying only visable windows with a title.
    For $i = 1 To $aList[0][0]
        If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
            ; Retrieve the handle of the Notepad window using the classname of Notepad.
            Local $hWnd = WinGetHandle($aList[$i][0])

            ; Retrieve the identifier of the thread and pass a variable to the $iPID parameter to store the PID.
            Local $iPID = 0
            Local $iThread = _WinAPI_GetWindowThreadProcessId($hWnd, $iPID)

            ; This is more than I needed for my text file... I just wanted the Processname... I post to be useful to others
            FileWrite($hFileOpen, ' Process thread:' & $iThread & '  Process ID (PID): ' & $iPID & "  Processname:" & _WinAPI_GetProcessName($iPID) & "  filename:" & _WinAPI_GetProcessFileName($iPID) & @CRLF)
        EndIf
    Next

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)
    ShellExecute($sFilePath)

EndFunc   ;==>Example

 

App: Au3toCmd              UDF: _SingleScript()                             

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