Windows – How to find all executable files in a windows directory

cmd.exewindows

I'm not sure of the commands or syntax needed to complete this but I thought it would be easy considering what I need it to do. Essentially I want to search C:\users\ for .exe files and output the computer name, path file was found so I know the user, and the .exe file into a log. I've been playing with for loops and Find. I just discovered the path command so I'm trying to understand that and how it can be used.

I'm so jumbled I wouldn't even know how to code this. I just know some of the bits that would go in it but I don't know them well enough to make anything work out of it. Any assistance or guidance would help a lot.

Oh and if possible I'd like to omit searching the users /temp folders or at least ignore any that are found there so they aren't in the log file.

Best Answer

To search folder C:\users\ for .exe files

dir C:\users\*.exe /s /b | find ^"temp^" /v /i | findstr /e .exe > UserExecutablePaths.txt

dir /s Lists the files in the folder and also the ones in the subfolders recursively.

dir /b Lists the subfolders/files names in bare format.

find /v exclude "temp" string

find /i not case sensitive

findstr /e : Matches the pattern .exe if at the end of a line

greater than ">" outputs to file UserExecutablePaths.txt

-EDIT-

Add computer name to file by using as you said echo %computername%

Use ampersand "&" to separate multiple commands on one command line and output to file change the greater than ">" from previous example to double ">>" so you dont overwrite the first output.

echo Computer Name = %computername% > UserExecutablePaths.txt & dir C:\users\*.exe /s /b | find ^"temp^" /v /i | findstr /e .exe >> UserExecutablePaths.txt
Related Question