Determine exactly what program file is being launched by examining program shortcut

How can I determine exactly what program file is being launched by examining the program's shortcut within Windows 10?

The exact path and filename of the program that is being launched aren't always intuitively obvious by examing the properties of the shortcut.

For example, the "Start in" section of the Adobe Acrobat XI Pro application is completely blank (see the screenshot).

So what is the best method to use to determine exactly what path and application is being launched when the program shortcut is clicked on?

Program shortcut
IT GuyNetwork EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JohnBusiness Consultant (Owner)Commented:
For Adobe, Properties, Shortcut and see "C:\Program Files (x86)\Adobe\Acrobat 2017\Acrobat\Acrobat.exe"

For Word 2016, same process, see "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE"

If the shortcut to open is a .LNK file, then it is probably not a good idea to open (at least I would not)

https://www.howtogeek.com/190897/how-can-you-open-and-edit-windows-.lnk-shortcut-files/
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
"Start in" can be empty, it is only used as the default path the program will use for searching files. Programs like Acrobat often have their own default path definitions, so don't need the "Start in" setting.

The important information is, as shown by John, the complete path to the application file stored in the shortcut in the same field as the executable name. There are some exceptions where the executable name is not stored in the shortcut - instead, it is a link to an installer file managing the application.
Paul SauvéRetiredCommented:
right click the shortcut on the start menu

hover on More (near top) and select Open File Location

you will now see the folder with the REAL shortcut - right click on this shortcut and select Properties

here is where VLC media player lives on MY PC:
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Seth SimmonsSr. Systems AdministratorCommented:
The exact path and filename of the program that is being launched aren't always intuitively obvious by examing the properties of the shortcut.

that's because the application installer (at least with adobe cc apps and microsoft office) create a CLSID shortcut
in the lnk file, it has the target as the CLSID as the application is described in the registry hence some of the buttons and text boxes are not available to be modified

well documented when searching for 'windows shortcut clsid'

For Adobe, Properties, Shortcut and see "C:\Program Files (x86)\Adobe\Acrobat 2017\Acrobat\Acrobat.exe"

that will vary on the version.  for me, acrobat is in C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe
same with office; can also vary by architecture.  mine is installed in C:\Program Files\Microsoft Office\root\Office16
oBdACommented:
These are called "advertised shortcuts"; you can drag the information out using PowerShell.
For advertised shortcuts, the property AdvertisedTargetPath will have the real target path.
Save it as Get-Shortcut.ps1 or Whatever.ps1; it supports pipeline input, so you can do something like that to find all advertised shortcuts:
gci "C:\ProgramData\Microsoft\Windows\Start Menu\*.lnk" -Recurse | .\Get-Shortcut.ps1 | ? {$_.AdvertisedTargetPath}

Open in new window

Or to see all the results in a GUI based table, where you can sort and filter, pipe the results further to Out-GridView:
gci "C:\ProgramData\Microsoft\Windows\Start Menu\*.lnk" -Recurse | .\Get-Shortcut.ps1 | Out-GridView

Open in new window

[CmdletBinding()]
Param(
	[Parameter(ValueFromPipeline=$true)]
	[string[]]$Path
)
Begin {
	$shell = New-Object -ComObject WScript.Shell
	$installer = New-Object -ComObject WindowsInstaller.Installer
}
Process {
	$Path | ForEach-Object {
		If ($item = Get-Item -Path $_ -ErrorAction SilentlyContinue) {
			If ($item.Extension -eq '.lnk') {
				$shortcut = $shell.CreateShortcut($_) | Select-Object -Property @{n='Name'; e={$item.BaseName}}, *, AdvertisedTargetPath
				If ($shortcut.TargetPath.ToLower().StartsWith("${env:Systemroot}\Installer\".ToLower())) {
					$shortcutTarget = $installer.GetType().InvokeMember('ShortcutTarget', 'GetProperty', $null, $installer, $item.FullName)
					$productCode = $shortcutTarget.GetType().InvokeMember('StringData', 'GetProperty', $null, $shortcutTarget, 1)
					$componentCode = $shortcutTarget.GetType().InvokeMember('StringData', 'GetProperty', $null, $shortcutTarget, 3)
					$shortcut.AdvertisedTargetPath = $installer.GetType().InvokeMember('ComponentPath', 'GetProperty', $null, $installer, @($productCode, $componentCode))
				}
				$shortcut
			} Else {
				Write-Error "Item '$($_)' is not a shortcut!"
			}
		} Else {
			Write-Error "Path '$($_)' not found!"
		}
	}
}
End {
	[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($shell)
	[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($installer)
}

Open in new window

IT GuyNetwork EngineerAuthor Commented:
oBda,

When I try to run this PowerShell command from within my Windows 10 PowerShell (which is running as an administrator) I simply get a blinking cursor and no output or messages are returned. I have verified that the excel.lnk file exists within the specified path and in fact, have copied this exact path into this PowerShell command.

Please let me know what I need to do to fix this so I will be able to run this PowerShell command. Do I need to load any special PowerShell consoles or do I need to run any other PowerShell commands before running the one(s) that you have provided?

gci "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\excel.lnk" -Recurse | .\Get-Shortcut.ps1 | Out-GridView

Open in new window


 Windows PowerShell command
IT GuyNetwork EngineerAuthor Commented:
Also what filename should I save this PowerShell file as?

I have given it different names such as "Get-Shortcut.ps1" or "1.ps1" and it still doesn't work.
oBdACommented:
If this is the first PowerShell script you ever run, open a PS console and enter
Set-ExecutionPolicy RemoteSigned -Force

Open in new window

Then for starters, save it as Get-Shortcut.ps1 in C:\Temp
Then run (Out-Gridview is not very useful for a single shortcut):
gci "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\*.lnk" -Recurse | ? {$_.BaseName -like "*Excel*"} | C:\Temp\Get-ShortcutNew.ps1

Open in new window

IT GuyNetwork EngineerAuthor Commented:
oBda,

I have done exactly what you have said and here are the results:

PS C:\temp> .\Get-Shortcut.ps1
C:\Temp\Get-ShortcutNew.ps1 : The term 'C:\Temp\Get-ShortcutNew.ps1' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At C:\temp\Get-Shortcut.ps1:1 char:111
+ ... curse | ? {$_.BaseName -like "*Excel*"} | C:\Temp\Get-ShortcutNew.ps1
+                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Temp\Get-ShortcutNew.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\temp> Get-Shortcut.ps1
Get-Shortcut.ps1 : The term 'Get-Shortcut.ps1' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Get-Shortcut.ps1
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Shortcut.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: The command Get-Shortcut.ps1 was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\Get-Shortcut.ps1". See "get-help about_Command_Precedence" for more details.
PS C:\temp>

Get-Shortcut.ps1 results
oBdACommented:
That was a copy and paste error; since the file is called Get-Shortcut.ps1, the last command must obviously be C:\Temp\Get-Shortcut.ps1, not C:\Temp\Get-ShortcutNew.ps1.
gci "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\*.lnk" -Recurse | ? {$_.BaseName -like "*Excel*"} | C:\Temp\Get-Shortcut.ps1

Open in new window

IT GuyNetwork EngineerAuthor Commented:
oBda,

I'm sorry I still don't understand what you mean.

Can you please repost everything again from start to finish including these PowerShell scripts, their names, their folder locations, and what they are supposed to do?

Thank you for your help and patience I am still learning the PowerShell.
oBdACommented:
Save the script as C:\Temp\Get-Shortcut.ps1
In a PowerShell console, enter
Set-ExecutionPolicy RemoteSigned -Force
gci "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\*.lnk" -Recurse | ? {$_.BaseName -like "*Excel*"} | C:\Temp\Get-Shortcut.ps1

Open in new window

IT GuyNetwork EngineerAuthor Commented:
Once again when I run this script (on either one of my Windows 10 computers) the script just hangs and never responds.

What needs to be done to fix this?

PowerShell-command
This happens both when I run the script exactly like it is posted above or if I edit it like this:

Set-ExecutionPolicy RemoteSigned -Force
gci "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\excel.lnk" -Recurse | ? {$_.BaseName -like "*Excel*"} | C:\Temp\Get-Shortcut.ps1

Open in new window

oBdACommented:
Found a small issue, but only with older versions of PowerShell.
This works from PS 2.0 on XP to PS 5.1 on Windows 10; save as C:\Temp\Get-Shortcut.ps1:
[CmdletBinding()]
Param(
	[Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
	[Alias('FullName')]
	[string[]]$Path
)
Begin {
	$shell = New-Object -ComObject WScript.Shell
	$installer = New-Object -ComObject WindowsInstaller.Installer
}
Process {
	$Path | ForEach-Object {
		If ($item = Get-Item -Path $_ -ErrorAction SilentlyContinue) {
			If ($item.Extension -eq '.lnk') {
				$shortcut = $shell.CreateShortcut($_) | Select-Object -Property @{n='Name'; e={$item.BaseName}}, *, AdvertisedTargetPath
				If ($shortcut.TargetPath.ToLower().StartsWith("${env:Systemroot}\Installer\".ToLower())) {
					$shortcutTarget = $installer.GetType().InvokeMember('ShortcutTarget', 'GetProperty', $null, $installer, $item.FullName)
					$productCode = $shortcutTarget.GetType().InvokeMember('StringData', 'GetProperty', $null, $shortcutTarget, 1)
					$componentCode = $shortcutTarget.GetType().InvokeMember('StringData', 'GetProperty', $null, $shortcutTarget, 3)
					$shortcut.AdvertisedTargetPath = $installer.GetType().InvokeMember('ComponentPath', 'GetProperty', $null, $installer, @($productCode, $componentCode))
				}
				$shortcut
			} Else {
				Write-Error "Item '$($_)' is not a shortcut!"
			}
		} Else {
			Write-Error "Path '$($_)' not found!"
		}
	}
}
End {
	[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($shell)
	[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($installer)
}

Open in new window

On Windows 10, to retrieve all 'All Users' shortcuts and show them in a table, run
gci "C:\ProgramData\Microsoft\Windows\Start Menu\Programs" -Filter *.lnk -Recurse | C:\Temp\Get-Shortcut.ps1 | Out-GridView

Open in new window

For the user specific shortcuts:
gci "$ENV:AppData\Microsoft\Windows\Start Menu\Programs" -Filter *.lnk -Recurse | C:\Temp\Get-Shortcut.ps1 | Out-GridView

Open in new window

Output sample (properties limited to Name and Path for readability):
Shortcuts in GridView

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IT GuyNetwork EngineerAuthor Commented:
oBda,

Great! This is exactly what I am looking for.

The one-line scripts work fine.

However, when I saved the longer script within the C:\Temp folder (as C:\Temp\Get-Shortcut.ps1) I get this error:

What needs to be done to fix this?

PS C:\temp> .\Get-Shortcut.ps1
Get-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\temp\Get-Shortcut.ps1:13 char:30
+         If ($item = Get-Item -Path $_ -ErrorAction SilentlyContinue)  ...
+                                    ~~
    + CategoryInfo          : InvalidData: (:) [Get-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\temp>

Get-Shortcut PowerShell error
oBdACommented:
Pass it a valid path of a .lnk file as argument. It doesn't actively search for files, that's what Get-ChildItem (alias gci, alias dir) is for.
C:\temp\Get-Shortcut.ps1 -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Calculator.lnk"

Open in new window

IT GuyNetwork EngineerAuthor Commented:
In which line of this PowerShell script do I provide the valid path of a .lnk file?
oBdACommented:
You could change line 5 to something like
	[string[]]$Path = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Calculator.lnk"

Open in new window

May I ask what the point of that would be?
IT GuyNetwork EngineerAuthor Commented:
Thank you!

This long script now works and returns the following information when I changed line 5 to
[string[]]$Path = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\paint.lnk"

Open in new window


PS C:\temp> .\Get-Shortcut.ps1


Name                 : paint
FullName             : C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\paint.lnk
Arguments            :
Description          : Create and edit drawings.
Hotkey               :
IconLocation         : %windir%\system32\mspaint.exe,0
RelativePath         :
TargetPath           : C:\WINDOWS\system32\mspaint.exe
WindowStyle          : 1
WorkingDirectory     :
AdvertisedTargetPath :

PS C:\temp>

PowerShell script results
IT GuyNetwork EngineerAuthor Commented:
oBdA,

Thank you very much for your help with this.

This is greatly appreciated.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 10

From novice to tech pro — start learning today.