Obtaining TargetPath of a shortcut without expanding environment variables

Welcome Forums General PowerShell Q&A Obtaining TargetPath of a shortcut without expanding environment variables

Viewing 0 reply threads
  • Author
    Posts
    • #160704
      Participant
      Topics: 3
      Replies: 1
      Points: 64
      Rank: Member

      Hey guys, I have a shortcut with the following target:

      %LOCALAPPDATA%\NirSoft\ControlMyMonitor\ControlMyMonitor.exe /LoadConfig "%LOCALAPPDATA%\NirSoft\ControlMyMonitor\Configs\Cinema.cfg" Primary

      However, when using WScript.Shell to obtain the link properties, I see;

      PS C:\Users\Fots> $wshShell = New-Object -ComObject WScript.Shell
      PS C:\Users\Fots> $wshShell.CreateShortcut('C:\Users\Fots\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\NirSoft\ControlMyMonitor Cinema.lnk')
      
      
      FullName         : C:\Users\Fots\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\NirSoft\ControlMyMonitor Cinema.lnk
      Arguments        : /LoadConfig "%LOCALAPPDATA%\NirSoft\ControlMyMonitor\Configs\Cinema.cfg" Primary
      Description      :
      Hotkey           : Alt+Ctrl+3
      IconLocation     : ,0
      RelativePath     :
      TargetPath       : C:\Users\Fots\AppData\Local\NirSoft\ControlMyMonitor\ControlMyMonitor.exe
      WindowStyle      : 1
      WorkingDirectory :

      Notice that the TargetPath has had %LOCALAPPDATA% expanded to the directory.

      Is there a way to obtain the TargetPath without expanding environment variables? (i.e. TargetPath should be %LOCALAPPDATA%\NirSoft\ControlMyMonitor\ControlMyMonitor.exe)

      Huge thanks in advance!!
      Fotis

Viewing 0 reply threads
  • The topic ‘Obtaining TargetPath of a shortcut without expanding environment variables’ is closed to new replies.