;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       AddShortcut() 
;; 
;;ACTION         Adds a shortcut to the specified location 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2007/03/27 
;; 
;;HISTORY        1.0  - 2007/03/27 - Initial Release 
;; 
;;SYNTAX         AddShortcut(Name, Group, Exe, Args, StartDir, IconPath, IconIndex, Public) 
;; 
;;PARAMETERS 
;;               Name 	   - REQUIRED - Name of shortcut 
;;		 Group	   - REQUIRED - Name of group to put the shortcut in. 
;;                                      Can be the special word "Desktop" 
;;		 Exe	   - REQUIRED - Path to the executable 
;;		 Args	   - OPTIONAL - Any executable arguments 
;;		 StartDir  - OPTIONAL - Folder to start the executable in 
;;		 IconPath  - OPTIONAL - File containing icon to use, default is the executable 
;;		 IconIndex - OPTIONAL-  Icon to use, default is first icon (0) 
;;		 Public	   - OPTIONAL-  Flag - true to use public (All Users) folders, 
;;                                      default is user folder 
;; 
;;REMARKS        This version sets focus to the root program group, allowing 
;;               items to be reliably found and moved. 
;; 
;;RETURNS        1 on success, 0 on failure, check exit status for specific error 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       ; Add notepad shortcut to all-users desktop 
;;               AddShortcut('My Notepad', 'Desktop', 'Notepad.exe',,,,1) 
; 
Function AddShortcut($_Name, $_Group, $_Exe, OPTIONAL $_Args, OPTIONAL $_StartD, OPTIONAL $_Icon, OPTIONAL $_IconIndex, OPTIONAL $_Public)
 
  Dim $_UProgs						; User "Start Menu\Programs" paths 
  Dim $_Dest						; destination path of new shortcut 
  Dim $_						; temp throwaway variable 
 
  $AddShortcut = 0
 
  ; Get the location for the current user's Programs folder 
  $_UProgs = ExpandEnvironmentVars(ReadValue('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Programs'))
 
  ; Create the new shortcut 
  $_ = ShowProgramGroup('', 8, 0)			; display the default program group - minimized 
  $_ = AddProgramItem($_Exe + " " + $_Args, $_Name, $_Icon, $_IconIndex, "" + $_StartD, 0, 0, 0)
  If @ERROR Exit 1 EndIf
 
  ; Verify it exists 
  If Not Exist($_UProgs + '\' + $_name + '.lnk')
    Exit 2						; not created - exit with error 
  EndIf
 
  ; OK - move the .lnk file to the desired location 
  If $_Group = 'Desktop'
    If $_Public
      $_Dest =  ExpandEnvironmentVars(ReadValue('HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Common Desktop'))
    Else
      $_Dest =  ExpandEnvironmentVars(ReadValue('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Desktop'))
    EndIf
  Else
    If $_Public
      $_Dest =  ExpandEnvironmentVars(ReadValue('HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Common Programs'))
    Else
      $_Dest =  $_UProgs
    EndIf
    $_Dest = $_Dest + '\' + $_Group
  EndIf
 
  ; if the Programs folder we set focus to earlier is present, close it 
  Sleep 0.5
  $_ = setFocus($_UProgs) 
  If Not @ERROR
    $_ = SendKeys('~{F4}')
  EndIf
 
  Move $_UProgs + '\' + $_name + '.lnk' $_Dest
  $AddShortcut = Not @ERROR
  Exit @ERROR
 
 
EndFunction