Advertisement
tankcr

Replace Icons

Feb 7th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-Shortcut {  
  2.     param(  
  3.         $path = $null  
  4.     )  
  5.      
  6.     $obj = New-Object -ComObject WScript.Shell  
  7.  
  8.     if ($path -eq $null) {  
  9.         $pathUser = [System.Environment]::GetFolderPath('StartMenu')  
  10.         $pathCommon = $obj.SpecialFolders.Item('AllUsersStartMenu')  
  11.         $path = dir $pathUser, $pathCommon -Filter *.lnk -Recurse  
  12.     }  
  13.     $path | ForEach-Object {  
  14.         $link = $obj.CreateShortcut($_.FullName)  
  15.  
  16.         $info = @{}  
  17.         $info.Hotkey = $link.Hotkey  
  18.         $info.TargetPath = $link.TargetPath  
  19.         $info.LinkPath = $link.FullName  
  20.         $info.Arguments = $link.Arguments  
  21.         $info.Target = try {Split-Path $info.TargetPath -Leaf } catch { 'n/a'}  
  22.         $info.Link = try { Split-Path $info.LinkPath -Leaf } catch { 'n/a'}  
  23.         $info.WindowStyle = $link.WindowStyle  
  24.         $info.IconLocation = $link.IconLocation  
  25.  
  26.         New-Object PSObject -Property $info  
  27.     }  
  28. }  
  29.  
  30. function Set-Shortcut {  
  31.     param(  
  32.     [Parameter(ValueFromPipelineByPropertyName=$true)]  
  33.     $LinkPath,  
  34.     $Hotkey,  
  35.     $IconLocation,  
  36.     $Arguments,  
  37.     $TargetPath  
  38.     )  
  39.     begin {  
  40.         $shell = New-Object -ComObject WScript.Shell  
  41.     }  
  42.      
  43.     process {  
  44.         $link = $shell.CreateShortcut($LinkPath)  
  45.  
  46.         $PSCmdlet.MyInvocation.BoundParameters.GetEnumerator() |  
  47.             Where-Object { $_.key -ne 'LinkPath' } |  
  48.             ForEach-Object { $link.$($_.key) = $_.value }  
  49.         $link.Save()  
  50.     }  
  51. }  
  52.  
  53. # assign F11 hotkey to PowerShell (uncomment line, make sure you have full admin privileges:  
  54. #Get-Shortcut | Where-Object { $_.LinkPath -like '*Windows PowerShell.lnk' } | Set-Shortcut -Hotkey F11
  55. [system.io.directory]::CreateDirectory("C:\Users\Public\Icons")
  56. c:
  57. $folderpath =split-path $myinvocation.mycommand.path
  58. copy icons\*.* C:\Users\Public\Icons
  59. $shortcuts = Get-Shortcut|Where-Object{$_.Link -ilike "*VMware*"}
  60. $icons = get-childitem "C:\Users\Public\Icons\"|Where-Object{$_.name -like "*.ico"}
  61. foreach($shortcut in $shortcuts)
  62. {
  63.     if (($shortcut.Link)-ilike $icons|Where-Object{$_.name -like "$*($shortcut.link)*"})
  64.     {
  65.         Write-host ("Icon exists for "+ $Shortcut.Link +" Applying now......") -foregroundcolor "green"
  66.  
  67.         $shortcut.IconLocation = ("C:\Users\Public\Icons\"+[io.path]::GetFileNameWithoutExtension($shortcut.Link)+".ico"+",0")
  68.     }
  69.     Else{write-host ("No Icon exists for "+ $Shortcut.Link +" Not Applying Changes") -foregroundcolor "yellow"}
  70. }
  71. $name = [io.path]::GetFileNameWithoutExtension($shortcut.Link)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement