Ever wondered what the path is to launch a given application? The Windows registry has a key that stores such information:

  $key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*", 
        "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*"

 $lookup = Get-ItemProperty -Path $key | 
 Select-Object -ExpandProperty '(Default)' -ErrorAction Ignore |
 Where-Object { $_ } |
 Sort-Object 

The result is a sorted list of registered application paths. You could easily turn this into a lookup hash table that takes the executable name and returns the full path:

$key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*", 
        "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*"

$lookup = Get-ItemProperty -Path $key | 
 Select-Object -ExpandProperty '(Default)' -ErrorAction Ignore |
 Where-Object { $_ } |
 Group-Object -Property { 
$_.Replace('"','').Split('\')[-1].ToLower() 
 } -AsHashTable -AsString 

You can now dump the list of registered applications:

 
PS> $lookup.Keys
outlook.exe
winword.exe
snagit32.exe
7zfm.exe
msoasb.exe 
...
 

Or you can translate the executable path to its real path:

 
PS> $lookup['excel.exe']
C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE
 



You are a PowerShell Professional, passionate about improving your code and skills? You take security seriously and are always looking for the latest advice and guidance to make your code more secure and faster? You’d love to connect to the vibrant PowerShell community and get in touch with other PowerShell Professionals to share tricks and experience? Then PowerShell Conference EU 2020 might be just the right place for you: https://psconf.eu (June 2-5, 2020 in Hanover, Germany).

It’s a unique mixture of classic conference with three parallel tracks filled with fast-paced PowerShell presentations, and advanced learning class with live discussions, Q&A and plenty of networking.

Secure your seat while they last: https://psconf.eu/register.html. The speakers and agenda is available here: https://psconf.eu/schedule.

Twitter This Tip! ReTweet this Tip!

Anonymous