;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       PinIt() 
;; 
;;ACTION         Pins a shortcut to the start menu 
;; 
;;AUTHOR         Mace 
;; 
;;CONTRIBUTORS   Glenn Barnas 
;; 
;;VERSION        1.2  - 2010/07/29 
;; 
;;HISTORY        1.0  - 2009-08-03 - Initial Release 
;;		 1.1  - 2009-12-02 - Glenn Barnas - make O/S-independent 
;;               (strip the "&" from the match string to make it O/S-independent. 
;;               1.2  - 2010/07/29 - Glenn Barnas - Add an optional arg to 
;;                                   specify the "Pin to" string 
;; 
;;SYNTAX         PinIt(Path, Name [, String]) 
;; 
;;PARAMETERS     Path - REQUIRED - String 
;;               - Full path to the .lnk shortcut file 
;; 
;;               Name   - REQUIRED - String 
;;               - The name of the shortcut on the start menu 
;; 
;;               String - OPTIONAL - String 
;;               - Alternate "Pin to start menu" string to 
;;               allow support for alternate languages or locations. 
;; 
;;REMARKS         
;; 
;;RETURNS        1 if success, 0 if failure. Check exit code for failure reason 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, VISTA, W2K3, W2K8, Win7 
;; 
;;EXAMPLES       PinIt('C:\Documents and Settings\All Users\Start Menu', 'Kix Script.lnk') 
; 
Function PinIt($strFldrPath, $strFileLnk, OPTIONAL $strText)
 
  Dim $objShell,$objFolder,$objFolderItem		; shell folder object pointers 
  Dim $colVerbs,$objVerb				; verb object pointers 
  Dim $strTarget					; target identifier 
 
  ; use the defined text if present, otherwise use default string 
  $strTarget = IIf($strText, $strText, "Pin to Start menu")
 
  $PinIt = 0						; default to return failure 
 
  If $strFldrPath = '' Or $strFileLnk = ''		; exit if bad args 
    Exit 87
  Endif
 
  If Not Exist($strFldrPath + '/' + $strFileLnk)	; exit if bad shortcut path 
    Exit 2
  Endif
 
  $objShell = CreateObject("Shell.Application")		; instantiate the objects 
  $objFolder = $objShell.Namespace($strFldrPath)
  $objFolderItem = $objFolder.ParseName($strFileLnk)
  $colVerbs = $objFolderItem.Verbs
  For Each $objVerb In $colVerbs			; enumerate the list 
    ; remove the "&", since Microsoft keeps moving it 
    If InStr(Join(Split($objVerb.name, '&'), ''), 'UnPin')
      $PinIt = 1					; return success - already pinned! 
      $objShell = ''					; destroy the object pointer 
      Exit 0						; exit success 
    Endif
 
    If Join(Split($objVerb.name, '&'), '') = $strTarget	; found? 
      $objVerb.DoIt
      $PinIt = 1					; return success 
      $objShell = ''					; destroy the object pointer 
      Exit 0						; exit success 
    Endif
  Next
 
  Exit 1						; general failure - exit 
 
EndFunction