Search code examples
windowsbatch-filefindstr

What is the location of FINDSTR on all Windows OS from Windows XP to Windows server 2012?


Is the directory of findstr always C:\Windows\system32\ for all OS from Windows XP to server 2012?

Or in other words is it safe to replace the following expression in a windows batch file:

findstr

to

C:\Windows\system32\findstr

Solution

  • Extra information just for completeness.

    Environment variable windir exists since Windows 95 and contains the path to Windows directory independent on which drive it is located and which name it has.

    For NT based Windows (NT4, Windows 2000, Windows XP, Vista, Windows 7 / 8 / 8.1) there is additionally the environment variable SystemRoot which contains also the path to Windows directory as this is the parent directory for the system directories

    • System32
    • Sysnative (only Windows x64 and only for 32-bit applications)
    • SysWOW64 (only Windows x64)

    For details about file system redirection read the File System Redirector page of Microsoft.

    It is not only safe to use either

    %windir%\System32\findstr.exe
    

    or

    %SystemRoot%\System32\findstr.exe
    

    I would highly recommend using always one of those two strings in batch files as then it does not depend which folders are in environment variable PATH and which file extensions in environment variable PATHEXT.

    There are some bad installers which add the folder path of the installed application to system environment variable PATH at beginning instead of appending at end and contain in the application's folder also find.exe or findstr.exe which are portings from Unix and therefore work completely different than find.exe and findstr.exe of Windows. AVRStudio is (or perhaps was as not verified with latest version of AVRStudio) an example breaking batch files of IT administrators not using always complete file name for Windows commands after installation.