[powershell] help creating shortcuts right

December 28, 2010 at 03:43:21
Specs: Windows 7
Write-Host $link $target $work
if ($link -and $target) {
$wshshell = New-Object -ComObject WScript.Shell
$link = $wshshell.CreateShortcut("$link")
$link.TargetPath = "$target"
} else {
Write-Host "Error: Insufficient parameters"
if ($work) {
$link.WorkingDirectory = "$work"
if ($icon) {
$link.IconLocation = "$icon"
if ($desc) {
$link.Description = "$desc"

That's a script I wrote long ago to create shortcuts. I need to update my script a little bit but I can't get it right for some reason. Problem right now is, I need to pass more complicated arguments to it.

%createlink% -link '%Public%\Desktop\71_Net.lnk' -target 'C:\Windows\explorer.exe shell:::{8E908FC9-BECC-40f6-915B-F4CA0E70D03D}'
%createlink% -link '%Public%\Desktop\72_Sys.lnk' -target '"%windir%\system32\rundll32.exe" Shell32.dll,Control_RunDLL Sysdm.cpl,,1'
%createlink% -link '%Public%\Desktop\73_Lang.lnk' -target '%windir%\system32\rundll32.exe Shell32.dll,Control_RunDLL Intl.cpl,,3'
%createlink% -link '%Public%\Desktop\81_DevM.lnk' -target '%windir%\system32\rundll32.exe devmgr.dll DeviceManager_Execute'

Problem 1: First one can't pass at all. Created shortcut has target field empty.
Problem 2: Second one creates shortcut with target: "%windir%\system32\rundll32.exe Shell32.dll,Control_RunDLL Sysdm.cpl,,1"

which should be:

"%windir%\system32\rundll32.exe" Shell32.dll,Control_RunDLL Sysdm.cpl,,1

Much obliged


See More: [powershell] help creating shortcuts right

Report •

December 28, 2010 at 18:55:10
You'll want to take a look at WScript.WshShortcut.Arguments. Basically, the path of the actual executable is pointed to by TargetPath. The rest of the command line goes into Arguments.

How To Ask Questions The Smart Way

Report •

December 29, 2010 at 07:18:59


Report •

Related Solutions

Ask Question