How do I edit the Target property in a shortcut to include a character after the file path using Powershell?

2.6k views Asked by At

To run a new, discrete instance of an application we have been manually creating a shortcut of the application .exe file and then editing the Target property of the shortcut to include a space and character(s) after the closing quote mark of the path, like this -

"C:\Program Files (x86)\Apps\MyApplication.exe" 2

When this shortcut is invoked it causes an entirely discrete instance of the application to run with it's own registry settings.

I want to automate the creation of the shortcut with a PowerShell script but using this -

$TargetFile = '"C:\Program Files (x86)\Apps\MyApplication.exe" 2'
$ShortcutFile = "C:\Users\USER1\Desktop\MyApplication.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = "C:\Program Files (x86)\Apps\MyApplication.exe"
$Shortcut.Save()

I find the Target property contains only the file path like this:

"C:\Program Files (x86)\Apps\MyApplication.exe"

without the appended 2.

1

There are 1 answers

0
ClumsyPuffin On

I am assuming that you want to pass parameter 2 along with the application.

You can try adding

$shortcut.Arguments = "2"

before the $Shortcut.Save().