Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been referring to answer number three of this post to write my PowerShell script, but it doesn't appear to be working.


$linkPath        = Join-Path ([Environment]::GetFolderPath("Desktop")) "My shortcut.lnk"
$targetPath      = Join-Path ([Environment]::GetFolderPath("MyDocuments")) "...\run.exe"
$link            = (New-Object -ComObject WScript.Shell).CreateShortcut($linkPath)
$link.TargetPath = $targetPath

It only prints out the code in the output pane but never seems to fully execute; no shortcut shows up on the desktop.

share|improve this question
    
Sorry, but it is better to edit the answer instead of editing original question. When I first read that, I did not understand your question, that is already solved, so the answer was unnecessary. So I saw on question edits what really happened. – kokbira Aug 31 '15 at 17:51
up vote 5 down vote accepted

You need to call the Save method of the shortcut object to actually store the shortcut as a file.

$linkPath        = Join-Path ([Environment]::GetFolderPath("Desktop")) "My shortcut.lnk"
$targetPath      = Join-Path ([Environment]::GetFolderPath("MyDocuments")) "...\run.exe"
$link            = (New-Object -ComObject WScript.Shell).CreateShortcut($linkPath)
$link.TargetPath = $targetPath

$link.Save()

See also:

share|improve this answer
    
Whoops, thank you for pointing that out! – Rob Jan 1 '12 at 15:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.