Find the path of notepad.exe and mspaint.exe

Heng-Cheong Leong picture Heng-Cheong Leong · Feb 6, 2009 · Viewed 94.1k times · Source

What is the best way to find out where notepad.exe and mspaint.exe are that will work across various versions of Windows?

Should I get the Windows directory via SHGetFolderPath(NULL, CSIDL_WINDOWS, NULL, SHGFP_TYPE_CURRENT, dir), and then traverse through all the subdirectories to look for the two files?

(Assume that I am not interested in anything outside the Windows folder.)

Answer

paxdiablo picture paxdiablo · Feb 6, 2009

This works on every Windows box I've got access to (XP+).

c:\> for %i in (cmd.exe) do @echo %~$PATH:i
C:\WINDOWS\system32\cmd.exe

c:\> for %i in (python.exe) do @echo %~$PATH:i
C:\Python25\python.exe

The great thing is, you don't have to use the actual %PATH%, you can substitute your own search path by using a different environment variable.