;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       SoftLink() 
;; 
;;ACTION         Creates a shortcut at path linking to file at targetpath 
;; 
;;AUTHOR         Lonkero 
;; 
;;CONTRIBUTORS   NTDoc, thanks for being there solving the issues 
;; 
;;VERSION        1.2.1 - 2005/12/22 
;; 
;;HISTORY        1.0   - 2002/01/31 - Original release 
;;               1.2.1 - 2005/12/22 - Removed a issue with novarsinstrings; 
;;                                    added some proper error output, original had 
;;                                    some weird issues that weren't there before. 
;; 
;;SYNTAX         SoftLink(Path,TargetPath[,Arguments[,StartDir[,IconPath]]]) 
;; 
;;PARAMETERS     Path - REQUIRED - String 
;;               - The fully qualified path to the new shortcut file. 
;;               TargetPath - REQUIRED - String 
;;               - The fully qualified path that the shortcut points to. 
;;               Arguments - OPTIONAL - String 
;;               - Arguments passed to $targetpath 
;;               StartDir - OPTIONAL - String 
;;               - Start directory (or Working Directory) of shortcut 
;;               IconPath - OPTIONAL - String 
;;               - The location of the icon used to represent the shortcut. 
;;               The string is of the form "path,index", where path is the full path 
;;               to the file containing the icon, and index is the zero-based index 
;;               of the icon within the specified icon file. 
;; 
;;REMARKS         
;; 
;;RETURNS        Nothing - @ERROR set to 0 (zero) on success or relevent error code on failure 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K3, W2K8, W2K12 
;; 
;;EXAMPLES       SoftLink("%userprofile%\desktop\my notepad.lnk","c:\winnt\system32\notepad.exe") get $ 
;;               SoftLink("%userprofile%\desktop\my notepad.lnk","c:\winnt\system32\notepad.exe","newdoc.txt") 
;;               SoftLink("%userprofile%\desktop\my notepad.lnk","c:\winnt\system32\notepad.exe","text.txt","c:\") 
;;               SoftLink("%userprofile%\bureau\my notepad.lnk","c:\winnt\system32\notepad.exe",,,"C:\winnt\system32\shell32.dll,3") 
; 
Function SoftLink($_path, $_target, optional $_args, $_startd, $_icon, $_IconIndex)
 
  Dim $_programs, $, $_name
 
  $_programs=ExpandEnvironmentVars(ReadValue('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Programs'))
  $_path=ExpandEnvironmentVars($_path)
  $_name=Split($_path,"\")
  $_name=$_name[UBound($_name)]
  $=AddProgramItem($_target+" "+$_args,Left($_name,InStr($_name,".lnk")-1),$_icon,$_iconIndex,""+$_startd,0,0,0)
 
  If Not Exist($_programs+"\"+$_name)
    $_programs=ExpandEnvironmentVars(ReadValue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Programs'))
  EndIf
  If @ERROR Exit @ERROR EndIf
 
  If Not Exist($_programs+"\"+$_name)
    Exit 2
  EndIf
 
  Copy $_programs+"\"+$_name $_path
  If @ERROR Exit @ERROR EndIf
 
  Del $_programs+"\"+$_name
  If @ERROR Exit @ERROR EndIf
 
  Exit 0
 
EndFunction