Finding Executable Paths on Windows Command Line

The Windows command line provides several ways to find the full path of an executable file. This can be useful when troubleshooting issues with commands or scripts, as it allows you to identify which version of a program is being used.

One way to find the path of an executable is by using the where command. This command searches for files in the directories specified by the PATH environment variable and returns their full paths. For example:

C:\> where edit
C:\Windows\System32\edit.com

The where command can also find multiple files with the same name but different extensions, as specified in the PATHEXT environment variable.

C:\> where notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe

In addition to finding executables by their exact names, the where command can also search for files using wildcards. For example:

C:\> where nt*.exe
C:\Windows\System32\ntoskrnl.exe
C:\Windows\System32\ntprint.exe
C:\Windows\System32\ntvdm.exe

Another way to find executable paths is by using Windows PowerShell’s Get-Command cmdlet. This cmdlet searches for commands in the directories specified by the PATH environment variable and returns their full paths.

PS C:\> Get-Command eventvwr

CommandType   Name          Definition
-----------   ----          ----------
Application   eventvwr.exe  c:\windows\system32\eventvwr.exe
Application   eventvwr.msc  c:\windows\system32\eventvwr.msc

The Get-Command cmdlet can also find commands by searching for patterns in their names. For example:

PS C:\> Get-Command *disk*

CommandType     Name                             Version    Source
-----------     ----                             -------    ------
Alias           Disable-PhysicalDiskIndication   2.0.0.0    Storage
Alias           Enable-PhysicalDiskIndication    2.0.0.0    Storage
Function        Add-PhysicalDisk                 2.0.0.0    Storage
Function        Add-VirtualDiskToMaskingSet      2.0.0.0    Storage
Function        Clear-Disk                       2.0.0.0    Storage
Cmdlet          Get-PmemDisk                     1.0.0.0    PersistentMemory
Cmdlet          New-PmemDisk                     1.0.0.0    PersistentMemory
Cmdlet          Remove-PmemDisk                  1.0.0.0    PersistentMemory
Application     diskmgmt.msc                     0.0.0.0    C:\WINDOWS\system32\diskmgmt.msc
Application     diskpart.exe                     10.0.17... C:\WINDOWS\system32\diskpart.exe

It’s worth noting that the where command and the Get-Command cmdlet have different behaviors when it comes to finding custom executables. The where command only searches for files with extensions specified in the PATHEXT environment variable, while the Get-Command cmdlet can find commands with any extension.

In summary, the Windows command line provides two main ways to find executable paths: the where command and the Get-Command cmdlet. Both tools are useful for troubleshooting issues with commands or scripts, but they have different behaviors when it comes to finding custom executables.

Leave a Reply

Your email address will not be published. Required fields are marked *