Page 1 of 1

.lnk shortcut - create programatically

Posted: 21 Oct 2023 04:52
by lazna
As far as VBS is marked as obsolete (and will be removed from next windows version), looking for alternative way of shortcut creation from batch file other than VBS script. Found powershell oneliner

Code: Select all

powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$shortcut = New-Object -ComObject WScript.Shell; $link = $shortcut.CreateShortcut('%shortpath%\short_%s_name%.lnk'); $link.TargetPath = '%target%'; $link.WorkingDirectory = '%workdir%'; $link.Arguments = '%params%'; $link.Description = '%desc%'; $link.IconLocation = '%icon%'; $link.WindowStyle = %windowstyle%; $link.Hotkey = '%hotkey_combination%+%letter%'; [console]::CursorVisible = $false; $link.Save()"
but look like this rely on WScript which is de-facto VBS. Does this powershell will work even after VBS engine will be removed?

Re: .lnk shortcut - create programatically

Posted: 21 Oct 2023 05:28
by aGerman
It's not VBS. It only uses the COM object WScript.Shell which is one out of many that can be instantiated in VBS but not only in VBS. I doubt that they are going to remove COM objects in the near future.

FWIW: MS is telling us that they are about to get rid of VBScript while I've not seen anything about similar intentions for JScript yet. At least I'm not aware of. What do they gain?

Steffen

Re: .lnk shortcut - create programatically

Posted: 22 Oct 2023 04:45
by lazna
thanks for explanation

Re: .lnk shortcut - create programatically

Posted: 22 Oct 2023 09:07
by DOSadnie
aGerman wrote:
21 Oct 2023 05:28
[...]
FWIW: MS is telling us that they are about to get rid of VBScript while I've not seen anything about similar intentions for JScript yet. At least I'm not aware of. What do they gain?
And why would they make it impossible to run VBS scripts, when BAT scripting has not been ditched long time after introduction of PS1?

Re: .lnk shortcut - create programatically

Posted: 22 Oct 2023 13:06
by lazna
DOSadnie wrote:
22 Oct 2023 09:07
aGerman wrote:
21 Oct 2023 05:28
[...]
FWIW: MS is telling us that they are about to get rid of VBScript while I've not seen anything about similar intentions for JScript yet. At least I'm not aware of. What do they gain?
And why would they make it impossible to run VBS scripts, when BAT scripting has not been ditched long time after introduction of PS1?
VBS will be an optional component, guessing for security reasons. About BAT scripting, read this

Re: .lnk shortcut - create programatically

Posted: 22 Oct 2023 13:40
by lazna
Just discovered the oneliner from first post of this thread display cursor if this one is intentionaly hidden by ANSI sequence, anybody have idea how to avoid this behaviour?