0

Hi I made this below gives no error but doesn't work either:

$cm = New-Object -ComObject WScript.Shell
$ls = $cm.CreateShortcut($env:appdata +
    "\xxx\xxx\xxx\xxx\xxx\mylink.lnk").TargetPath

What am I doing wrong?

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
user2170776
  • 133
  • 4
  • are you trying to create a link or get target of link – ArcSet Feb 11 '19 at 19:07
  • I am trying to get the TargetPath of a .lnk file – user2170776 Feb 11 '19 at 19:10
  • I would say u are not writing out the $LS or if you are displaying $LS then the link doesnt exist – ArcSet Feb 11 '19 at 19:13
  • @ArcSet - The proposed duplicate has the answer. The querent is strongly encouraged to check it. – Jeff Zeitlin Feb 11 '19 at 19:14
  • @JeffZeitlin Thats not the error he has. He has the correct code. He just didnt ether display $ls or Shortcut doesnt exist. He literally has the same solution from that page here. – ArcSet Feb 11 '19 at 19:21
  • @ArcSet - He does _not_ have the correct code. Look _carefully_ at the difference between his code, above, and the accepted answer to the duplicate. It turned out that quotes matter. – Jeff Zeitlin Feb 11 '19 at 19:22
  • @JeffZeitlin literally ran his code and just replaced his location with mine and it works. So his is working. `$cm = New-Object -ComObject WScript.Shell; $cm.CreateShortcut($env:appdata + "\Test\test.txt.lnk").TargetPath` returned `C:\TEST\test.txt` – ArcSet Feb 11 '19 at 19:26
  • @ArcSet - What version of PowerShell are you using - when I run it here, the quotes matter. – Jeff Zeitlin Feb 11 '19 at 19:29
  • @JeffZeitlin 5.1 – ArcSet Feb 11 '19 at 19:30
  • @ArcSet - Odd... so am I. – Jeff Zeitlin Feb 11 '19 at 19:31
  • @JeffZeitlin I also see that he is storing the return into a variable but doesnt show that variable being called. Could be as simple as he didnt display the answer.... or the link doesnt exist. It doesnt seem like a duplicate. lol but it really doesnt matter. Ill drop it – ArcSet Feb 11 '19 at 19:33
  • @ArcSet - One would presume that the querent knows what he's doing at that level; if the flagged duplicate isn't in fact what his question is, he needs to edit this question to be more explicit and ask that it be reopened. – Jeff Zeitlin Feb 11 '19 at 19:34
  • @JeffZeitlin I always have a hard time determining how skilled someone is at a post like this becuase its such a common snippit anyone can get it without knowing anything. But fair enough fair enough – ArcSet Feb 11 '19 at 19:37

0 Answers0