pctechtv Posted April 13, 2020 Share Posted April 13, 2020 (edited) 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 Edited April 13, 2020 by pctechtv Link to comment Share on other sites More sharing options...
Developers Jos Posted April 13, 2020 Developers Share Posted April 13, 2020 This is how to get the EXE name for a shown window: SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted April 13, 2020 Share Posted April 13, 2020 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Deye Posted April 13, 2020 Share Posted April 13, 2020 (edited) 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 April 13, 2020 by Deye Link to comment Share on other sites More sharing options...
pctechtv Posted April 13, 2020 Author Share Posted April 13, 2020 Jos, Nine, and Deye thank you for the replies. All that post is helpful. I am reading more now getting closer. 😀 Link to comment Share on other sites More sharing options...
pctechtv Posted April 13, 2020 Author Share Posted April 13, 2020 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 expandcollapse popup#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 Exit 1 Link to comment Share on other sites More sharing options...
Exit Posted April 13, 2020 Share Posted April 13, 2020 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: expandcollapse popup#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 FrancescoDiMuro 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now