New-ADTShortcut

hi,

can you please give me advice howto make a shortcut to a store app?
for example the company portal?
tried to run:
get-adtshortcut -LiteralPath "c:\data\Company Portal.lnk"
from a link I created, but got this error:
Get-ADTShortcut: Exception calling ".ctor" with "10" argument(s): "Invalid target path provided for the shortcut."

thanks for help

Greg

Your syntax for Get-ADTShortcut appears to be correct:

You could use New-ADTShortcut to create a new shortcut

You can also use Set-ADTShortcut to modify an existing shortcut

So troubleshooting why it is not working...

Two questions:

  1. Is the LiteralPath to the shortcut correct?
  2. Does the account that is running the command have permissions to see the file "c:\data\Company Portal.lnk"?

both questions are yes, I try to find the target path for Store apps like Company Portal for use with new-adtshortcut...


this is the lnk settings.

Just been doing a bit of web research...

I think if you set the Target Path to shell:AppsFolder\Microsoft.CompanyPortal_8wekyb3d8bbwe!App you may find it works.

This should work, but note the caveats below

New-ADTShortcut -LiteralPath 'C:\Users\Public\Public Desktop\Company Portal.lnk' -TargetPath "shell:AppsFolder\Microsoft.CompanyPortal_8wekyb3d8bbwe!App" -IconLocation "https://deviceadvice.io/wp-content/uploads/2020/08/CompanyPortalApp.ico" -Description "Company Portal"

Microsoft appear to have made some changes to the way shortcuts can be created in certain folders :man_shrugging:
When I ran the above, the shortcut was created, but my other 4 .lnk files disappeared :worried: ,
However opening C:\Users\Public\Desktop opens and redirects to C:\Users\Public\Public Desktop - this showed my previous 4 .lnk files but the new Company Portal.lnk was not there :confused:
Our users desktops are redirected to their OneDrive C:\Users\<USER>\OneDrive - <COMPANYNAME>\Desktop, and I could successfully create the shortcut in there.

However... the icon is not assigned correctly, the reason behind this appears to be that it needs to be in BASE64 format, you could either use this: Powershell shortcut with custom embedded icon - Programming & Development - Spiceworks Community or another example here to copy the ico locally first and then assign to the shortcut: Reddit - Please wait for verification

I hope this helps?

hi,
thanks for the code and the explanation of the problem
Greg

It's probably worth mentioning that 4.2.0 contains rewritten shortcut code to use proper IShellLinkW code: IShellLinkW (shobjidl_core.h) - Win32 apps | Microsoft Learn.

Our current implementation provides the same level of configuration as we've previously had, but we've got options in the future for creating our own MSI advertised shortcuts, among other things.

The main reason for mentioning this is that all of the malarkey above around icon transparency and who knows what else may very well just disappear simply because we're using a proper implementation via actual Win32 API code.

The same goes for our .url support, which now uses IUniformResourceLocatorW under the hood, the same as what the operating system uses. No more reading .url files like they're an INI file, everthing's done properly now.