1

I've got a script that is currently using a WScript.Shell COM object to create a shortcut.

$shortcut = (New-Object -ComObject WScript.Shell).Createshortcut("$shortcutFolder\target.lnk")

Unfortunately, setting the target path of the shortcut...:

$shortcut.TargetPath = $targetPath

...is taking a very long time (30 to 75 seconds) if it has not been done previously in the current Powershell session. If, however, the command is run again, its time to execute is on the order of milliseconds as it should be.

Is there another, maybe native, way to accomplish this that will work better? Alternatively, is there anything I can do to speed this process up? I've got a Process Monitor trace, but I haven't been able to glean much from it.

1
  • Works very quickly for me...what does $targetPath contain? Commented Oct 11, 2012 at 14:01

1 Answer 1

1

IIRC the WScript API is just a thin layer on top of the IShellLink COM interface which is what we use in our New-Shortcut cmdlet in the PowerShell Community Extensions. What is the type in $targetPath e.g. what type info does this return:

$targetPath | get-member
Sign up to request clarification or add additional context in comments.

1 Comment

It looks like I was barking up the wrong tree with regards to performance, but you've answered my original question. Thanks.

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.