Launch a shortcut using batch file
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Ocean Floor
--
Chapters
00:00 Launch A Shortcut Using Batch File
00:35 Accepted Answer Score 7
01:31 Answer 2 Score 0
01:55 Thank you
--
Full question
https://superuser.com/questions/552625/l...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#shortcuts #batchfile #wildcards
#avk47
ACCEPTED ANSWER
Score 7
You can use either for or forfiles for this task. Forfiles is more flexible, but it might not work properly on older versions of Windows.
For
From a command prompt:
for %a in ("C:\Documents and Settings\All Users\Desktop\Remote agent *.lnk") do @start "" "%a"
In a batch file:
for %%a in ("C:\Documents and Settings\All Users\Desktop\Remote agent *.lnk") do @start "" "%%a"
Forfiles
forfiles /P "C:\Documents and Settings\All Users\Desktop" /M "Remote agent *.lnk" /C "cmd /C start \"\" @path"
Forfiles goes through all files in the path specified in /P
that match the mask specified on /M
and executes the command specified in /C
. Here @path
is the full path of the file.
Normally, we'd use the command start "" "Remote Agent 1234.lnk"
to launch the shortcut. Since start is an internal command, we have to call it in a new shell (cmd /C
). \"\"
are just escaped double quotes, since the entire string is already quoted.
ANSWER 2
Score 0
According to HELP START program/command must NOT have double quotes. i.e. only *for %%a in ("C:\Documents and Settings\All Users\Desktop\Remote agent .lnk") do @start /D"%%~dpa" %%~nxa works correctly!