Creating Windows shortcuts with Powershell, problems with spaces in the target path

Short and sweet, I make shortcuts in PS, until the Target Path has a place in it, the shortcut works fine. As soon as Target has a place in it, the target shortcut is wrapped in double quotes and, as such, does not work ... Below is the non-working code. If you were to remove the space, that would be correct (well, except that it does not point to the EXE at that point). Basically, this will not wrap the target in quotation marks.

$shell = New-Object -ComObject WScript.Shell $shortcutX = $shell.CreateShortcut("C:\Short.lnk") $shortcutX.TargetPath = "C:\apps\application --switch" $shortcutX.Save() 

TL DR:

Works.

$ shortcutX.TargetPath = "C: \ apps \ application"

Does not work!

$ shortcutX.TargetPath = "C: \ apps \ application -switch"

Why?!?!?!?!

+4
source share
1 answer

From MSDN :

This property is only for the target shortcut route.

You can add arguments to the shortcut in the Argument property.

 $shortcutX.Arguments = "-- switch" 

In my drawer (Windows 7 Pro), I can make a shortcut with a path destination that has spaces.

+6
source

Source: https://habr.com/ru/post/1402519/


All Articles