Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Shortcut Powershell Quirks

$
0
0

Hi

I am using PowerGUI and running the code below

The C drive entries come out file, path, destination, owner

However in the D drive the destination value ($LinkTarget) is mainly empty, because the
   $LinkObject = $Shell.CreateShortcut($ShortcutName)
is null

I don't understand what could be going on, i am an admin on my machine and have similat access to both the C: and D: drives.

>> Is there such a thing as "OLD STYLE" shortcuts ?

One that did not work was 299 bytes, the one that did was 663 bytes and i the differences in path lengths are nothing like 360 bytes.

# PowerShell function to list Start Menu Shortcuts
Clear-Host
#$ErrorActionPreference = "SilentlyContinue"
$Shell = New-Object -ComObject WScript.Shell 

Function Get-AllLinks([string]$path){

Get-ChildItem $Path -Include *.lnk -Recurse  |
ForEach-Object {
  $Shortcut = $_
  $objectFile = Get-Acl $Shortcut.FullName
   $ShortcutName = $Shortcut.FullName
   $LinkObject = $Shell.CreateShortcut($ShortcutName)
   $LinkTarget = $LinkObject.targetpath
   $Owner = $objectFile.Owner
   Write-Output $ShortcutName", "$LinkTarget", "$Owner

  } 
 } 

$Drives = @("C", "D")

Foreach($i in $Drives)
{
	[string]$name = "c:\temp3\"+$i+"_links.txt"
	Get-AllLinks $i":\" | Out-File $name
}

[Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null

Thanks



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>