0

As the title says, but here's an image for a visual explanation.

I like the idea of doing this via a batch script. (as I am somewhat familiar with batch scripts and find them quite readable, so that way I can more easily make changes and/or re-use code in the future)

However, I am not opposed to other hybrid solutions or a different solution entirely. The one requirement I do have is that it must run on modern Windows computers without requiring additional installs beyond updates.

Below you can find my current code (source), but please note that this does not yet meet all my criteria as I ran out of both batch and google-fu skills:

@echo off

set "des=%~dp0\_shortcuts"
set "src=%~dp0"

setlocal enabledelayedexpansion
for /r "%src%" %%A in (*.exe) do (
    set "exe=%%A"
    set "name=%%~nA"

    set "SCRIPT=%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"

    echo Set oWS = WScript.CreateObject^("WScript.Shell"^) >> !SCRIPT!
    echo sLinkFile = "%des%\!name!.lnk" >> !SCRIPT!
    echo Set oLink = oWS.CreateShortcut^(sLinkFile^) >> !SCRIPT!
    echo oLink.TargetPath = "!exe!" >> !SCRIPT!
    echo oLink.Save >> !SCRIPT!

    cscript /nologo !SCRIPT!
    del !SCRIPT!

)
PAUSE

With the above code, I am getting an error like below for each shortcut it tries to create:

C:\Users\mica\AppData\Local\Temp\24172-1508-16791-17305.vbs(5, 1) WshShortcut.Save: Unable to save shortcut "C:\Users\mica\OneDrive\Documents_create shortcuts_shortcuts\in-test1-folder.lnk".

I gather it's an elevation issue, so I tried to implement this code to fix the issue, but I was unsuccessful.

If anyone can help complete the code or has better solutions, please do share! Also, do let me know if I forgot to mention anything.

2
  • Does it have to be shortcuts? What about symbolic links with the mklink tool? Commented Oct 28, 2022 at 9:58
  • Can you remove the "del !SCRIPT!" part and show what the vbs looks like from inside? Commented Oct 28, 2022 at 10:11

0

You must log in to answer this question.

Browse other questions tagged .