ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

auto create .lnk shortcuts for all currently installed Windows Store Apps

(1/3) > >>

Nod5:
Coding Snack request
a script/tool that auto creates .lnk shortcuts for all currently installed Windows Store Apps.

Background
Users of Mouser's Find And Run Robot (FARR) requested an easy way to launch Windows Store Apps. The problem is that those apps do not create .lnk shortcut files FARR can find when searching files and folders. Users can manually create .lnk shortcuts one by one. But an automated method would be more user friendly. A standalone tool could also be useful for people who don't use FARR.

Research done

1. syntax for .lnk shortcuts to Windows Store Apps

Windows Store Apps can  be run from .lnk shortcuts with a target that has this format

--- ---explorer.exe shell:Appsfolder\<AUMID>where AUMID (Application User Model ID) is a special string for each app.
For example on my PC we can launch Windows Calculator with

--- ---explorer.exe shell:Appsfolder\Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
2. Powershell command to get a list of AUMID
The Powershell command

--- ---get-StartAppsreturns a list with an App name and its associated App AUMID on each line.
More details here https://docs.microsoft.com/en-us/windows/configuration/find-the-application-user-model-id-of-an-installed-app

3. Making .lnk shortcuts programmatically
AutoHotkey has the command FileCreateShortcut, https://autohotkey.com/docs/commands/FileCreateShortcut.htm

What has already been tried
I didn't find a working way to use AutoHotkey to run Powershell with the get-StartApps command and output the resulting list to a .txt file.
I get this error

--- ---'get-StartApps' is not recognized as the name of a cmdlet
Instead of banging my non-powershell experienced head more against powershell error message walls, perhaps someone else here can think of a quick fix or different solution, using AutoHotkey, Powershell or some other method?  :)

4wd:
Simple Powershell script, it'll create an "Installed-Apps" folder on the Desktop and populate it with shortcuts for installed ... err ... apps.

For this purpose it regards any AUMID that contains a ! and doesn't end in .exe as a valid app - as distinct from every program installed.

Run it from a Powershell console using: .\Apps2Shortcut.ps1

For some reason I couldn't get it to run from a shortcut but that's probably my fault.

You will probably get an error if you run the extracted script from the archive due to Execution Policy, there are 3 solutions:

* Copy/Paste the script below as a new script
* Mark the script as trusted, (it has a zone identifier in its ADS which marks it as not from the local machine)
* Change your Execution Policy using Set-ExecutionPolicy
Standard Disclaimer: Works for me  :)


--- Code: PowerShell ---<#  Apps2Shortcut.ps1#>Function Create-Shortcut {  param (    [string]$name,    [string]$aumid  )  # Create a Shortcut with Windows PowerShell  $WScriptShell = New-Object -ComObject WScript.Shell  $Shortcut = $WScriptShell.CreateShortcut($name)  $Shortcut.TargetPath = "$env:SystemRoot\explorer.exe"  $Shortcut.Arguments = "shell:Appsfolder\$($aumid)"  $Shortcut.Save()} $DesktopPath = [Environment]::GetFolderPath("Desktop") if (!(Test-Path "$($DesktopPath)\Installed-Apps")) {  New-Item "$($DesktopPath)\Installed-Apps" -ItemType Directory | Out-Null} $apps = (Get-StartApps)for ($i = 0; $i -lt $apps.Count; $i++) {  if (($apps[$i].AppID).contains("!") -and (($apps[$i].AppID).Substring(($apps[$i].AppID).Length - 4) -ne '.exe')) {    Create-Shortcut "$($DesktopPath)\Installed-Apps\$($apps[$i].Name).lnk" $apps[$i].AppID   }}
Hopefully you'll end up with something like this:

auto create .lnk shortcuts for all currently installed Windows Store Apps

To run a Powershell command from AHK you'll probably need to use: powershell.exe -C "Get-StartApps | Out-File D:\test.txt"

Use -C to run commands directly, -F to run a script.

Nod5:
Simple Powershell script
-4wd (April 01, 2019, 04:40 AM)
--- End quote ---
Great!

To get the script to work on my PC I had to do these things
- the multi line comments at the top gave errors, but changing /* and */ to <# and #> fixed that.
- run the cmd window as administrator
- add the Bypass argument, like so

--- ---powershell.exe -ExecutionPolicy Bypass -F C:\folder\Apps2Shortcut.ps1Then it works and outputs .lnk shortcut files in the desktop folder "Installed-Apps". Nice!

But I can't get it to run within AutoHotkey, even as administrator. I've tried

--- ---Run powershell.exe -ExecutionPolicy Bypass -F C:\folder\Apps2Shortcut.ps1
Run powershell.exe -ExecutionPolicy Bypass -NoExit -F C:\folder\Apps2Shortcut.ps1
RunWait powershell.exe -ExecutionPolicy Bypass -NoExit -F C:\folder\Apps2Shortcut.ps1and some other variations without success. Similarly, this and variations of it also do not work

--- ---Run powershell.exe -ExecutionPolicy Bypass -C "Get-StartApps | Out-File C:\folder\test.txt"I don't have to use AutoHotkey of course. But remaining issues I'm trying to solve are
1. how to automatically run the script at least every time Windows starts, to keep the .lnk files up to date?
2. how to make it easy for end users (ideally not running as administrator) to set this up once and for all?
And also
3. is there some way to add the matching icons to the shortcuts?

edit:
This handles issue 1 above. Run the AutoHotkey script as administrator creates a scheduled task that in turn on each logon runs the powershell script to create .lnk files.

--- ---RunWait schtasks /Create /SC ONLOGON /TN Apps2Shortcut /TR "powershell.exe -ExecutionPolicy Bypass -F C:\folder\Apps2Shortcut.ps1"The same task can also be created manually (and deleted if no longer needed) through the Task Scheduler (win+I and search for "schedule tasks").
Not a very end-user friendly way to set this up though.

edit2:
This Python solution works for me without running as administrator https://stackoverflow.com/a/43635956
I had to use Python 2. The .lnk shortcut files also get icons (issue 3 above).
Perhaps the approach there can be reproduced without Python.

4wd:
To get the script to work on my PC I had to do these things
- the multi line comments at the top gave errors, but changing /* and */ to <# and #> fixed that.-Nod5 (April 01, 2019, 10:18 AM)
--- End quote ---

Ooops, my bad, I added the comment after pasting into the post ... should've tested it.
I've updated the code/archive.
 
- run the cmd window as administrator
- add the Bypass argument, like so
--- End quote ---

Wasn't necessary if run from a PowerShell console, even just right-click on the script and choose Run with Powershell but you'd bump up against the ExecutionPolicy restriction - which does get to be a real PITA sometimes.  In theory you can right-click->Properties and select something like Trust this file under the Security tab ... but I haven't seen it for awhile so I may be mis-remembering.

Shouldn't need Admin privileges since you're only writing to a directory that the user owns anyway ... just tried it here, no Admin required, just had to answer '(Y)es' to the ExecutionPolicy question that pops up.

The same task can also be created manually (and deleted if no longer needed) through the Task Scheduler (win+I and search for "schedule tasks").
Not a very end-user friendly way to set this up though.
--- End quote ---

Perhaps this post which shows setting/deleting a scheduled task in Powershell may help?

Give the task a static name and have the script just check if it's there at each run using schtasks /query <taskname>, implement if it isn't and have an optional argument to the script Apps2Shortcut.ps1 -Remove to remove it if the task is no longer required.

mouser:
Very cool -- thank you for this  :up: :up:

Navigation

[0] Message Index

[#] Next page

Go to full version