2

I am trying to create a short cut on public desktop for users, but this target path for this short cut is causing some issues.

$wshshell = New-Object -ComObject WScript.shell

$desktop = [System.Environment]::GetFolderPath("desktop")

$lnk = $wshshell.CreateShortcut("$desktop\CLMCPDEDEV.lnk")

$lnk.TargetPath = "C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe" "configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg"

I have the config file in another folder and exe is in a different path. I'm new to power shell, how do I bypass that space between "C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe" and "configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg"? That's the full short cut path when I do this manually. Any guidance is much appreciated.

1
  • Does putting a single quote before "C: and after .cfg" help? Commented Aug 28, 2015 at 13:26

1 Answer 1

4

Quote from CreateShortcut method documentation:

A common problem is putting arguments in the TargetPath property of the shortcut object, which doesn't work. All arguments to the shortcut must be put in the Arguments property.

So you have to do this:

$wshshell = New-Object -ComObject WScript.shell

$desktop = [System.Environment]::GetFolderPath('Desktop')

$lnk = $wshshell.CreateShortcut((Join-Path -Path $desktop -ChildPath 'CLMCPDEDEV.lnk'))

$lnk.TargetPath = 'C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe'
$lnk.Arguments = 'configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg'

$lnk.Save()
Sign up to request clarification or add additional context in comments.

4 Comments

That worked and to move the short cut to public I used the typical cmd /c xcopy %userprofile%\desktop\CLMCPDEDEV.lnk c:\users\public\desktop and then cmd /c del %userprofile%\desktop\CLMCPDEDEV.lnk to avoid duplicate icons
Hi BeatCracker. What command would I use if I want to change the short cut icon to the specific lnk above in the public desktop? I have a ICO file in a folder that is a different color that I want clmcpdedev.lnk to use?
Actually when changing the icons for shortcut on one machine and using a script to delete the original icons then copying the new icons to the target machine, the icons stay for awhile and then break and become generic. Do I have to use iconlocation argument?
@joextreme: you can specify the icon location with $lnk.IconLocation = 'C:\Program Files (x86)\Unisys\WebEnabler\web enabler.ico',0 (assuming this is the icon file location) The "0" argument means specify the icon in the first position, which is required for non-embedded icon definitions. BTW, this post finally fixed my problem with creating a link. The magic stuff here is the $lnk.Arguments which I was missing when specifying cmd /K "...." command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.