;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       wshShortCut() 
;; 
;;ACTION         Creates Shortcuts for files or Web pages 
;; 
;;AUTHOR         Shawn, Radimus, Al_Po, Richard Farthing, NTDOC 
;; 
;;CONTRIBUTORS    
;; 
;;VERSION        1.3.4 
;; 
;;               1.0 -   Initial Release 
;;               1.1   - fixes a logic bug in wshShortCut 1.0 so you can use more than 
;;                       icons 0-9 in a icon library on URLS. 
;;                       Unless path is explicity stated in $_ShortCutName, icons are created 
;;                       on the desktop. 
;;                       If .lnk or .url is omitted, UDF tries to determine the shortcut type, 
;;                       but defaults to .lnk If it can't figure it out. 
;;               1.2   - Support for NoVarsinStrings; Checks for existence of TargetPath 
;;                       in .lnk files. Included option for Description (.description) 
;;               1.3   - Attempts to create directory structure to shortcut If it does  not exist. 
;;               1.3.1 - Bug Fixes when creating URL shortcuts. 
;;               1.3.2 - Included Option for HotKey(.hotkey). 
;;               1.3.3 - Added option to bypass TARGETPATH exist check on LNK shortcuts. 
;;                       Add ,1 to the end of your Targetpath to bypass. 
;;                       See Example below. 
;;               1.3.4 - Dimmed undimmed var. 
;; 
;;SYNTAX         wshShortCut(shortcutname, targetpath [,arguments] [,startdir] [,iconpath] [,style] [,Description])    
;; 
;;PARAMETERS     SHORTCUTNAME - Required - String 
;;               - Name of Shortcut. If path is omitted, will be saved to desktop. 
;; 
;;               TARGETPATH - Required - String 
;;               - The path the target point to.  To ommit checking If path exists 
;;               in the function, append the target path with ",1" 
;; 
;;               ARGUMENTS - Optional - String 
;;               - Arguments appended to TARGETPATH 
;; 
;;               STARTDIR - Optional - String 
;;               - Working Directory 
;; 
;;               ICONPATH - Optional - String 
;;               - Path to Icon Library. To specIfy an icon other than the first, 
;;               separate the icon path with ",#" where # represents the icon in the library. 
;; 
;;               STYLE - Optional - Integer 
;;               - 1 = default, 3 = maximized window, 7 = minimized window 
;; 
;;               DESCRIPTION - Optional - String 
;;               - Description or Comment about Shortcut 
;; 
;;               HOTKEY - Optional - String 
;;               - Keyboard Hotkey. 
;;               Note: Shortcut must be saved to desktop or startmenu for Hotkey to function 
;; 
;;REMARKS         
;; 
;;RETURNS        1 on Success, 0 on failure 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K3, W2K8, W2K12 
;; 
;;EXAMPLES       $_=wshShortcut("KiXtart Web Page","http://www.kixtart.org")    
;;               $_=wshShortcut("Notepad","%systemroot%\system32\notepad.exe")    
;;               $_=wshShortcut("Server1","\\Server1,1")  
; 
Function wshShortCut($_ShortcutName, $_TargetPath, Optional $_Arguments, Optional $_StartDir, Optional $_IconPath, Optional $_Style, Optional $_Description, Optional $_Hotkey)
 
  Dim $_Shell, $_Desktop, $_Shortcut, $_Index, $_IconIndex, $_ScDir, $_Rc
 
  $wshShortcut = 0
 
  $_Shell = CreateObject('wscript.shell')
  
  If $_Shell
    If UCase(Right($_ShortcutName, 4)) = '.URL' Or UCase(Right($_ShortcutName,4 )) = '.LNK'
      ;do nothing  
    Else
      If UCase(Left($_TargetPath, 5)) = 'HTTP:' Or UCase(Left($_TargetPath, 6)) = 'HTTPS:' Or UCase(Left($_TargetPath, 4)) = 'FTP:'
        $_ShortcutName = $_ShortcutName + '.url'
      Else
        $_ShortcutName = $_ShortcutName + '.lnk'
      EndIf
    EndIf
    
    If InStr($_TargetPath, ',')
      $_TargetPath = Split($_TargetPath, ',')[0]
    Else
      If InStr($_ShortcutName,'.lnk') And Not Exist($_TargetPath)
        Exit 2
      EndIf
    EndIf
    
    If InStr($_ShortcutName,'\') = 0
      $_Desktop = $_Shell.SpecialFolders('Desktop')
      $_ShortcutName = $_Desktop + '\' + $_ShortcutName
    Else
      $_ScDir = SubStr($_ShortcutName, 1 ,InStrRev($_ShortcutName, '\'))
      If Not Exist($_ScDir)
        MD $_ScDir
        If @ERROR
          Exit @ERROR
        EndIf
      EndIf
    EndIf
    
    $_Shortcut = $_Shell.createshortcut($_ShortcutName)
    If $_Shortcut
      $_Shortcut.targetpath = $_TargetPath
      If $_IconPath And InStrRev($_ShortcutName,'.lnk')
        $_Shortcut.iconlocation = $_IconPath
      EndIf
      If $_Arguments
        $_Shortcut.arguments = $_Arguments
      EndIf
      If $_StartDir
        $_Shortcut.workingdirectory = $_StartDir
      EndIf
      If $_Style
        $_Shortcut.windowstyle = $_Style
      EndIf
      If $_Description And InStrRev($_ShortcutName,'.lnk')
	  $_Shortcut.description = $_Description
      EndIf
      If $_Hotkey
        $_Shortcut.hotkey = $_Hotkey
      EndIf
      $_Shortcut.save
      If @ERROR
        Exit @ERROR
      EndIf
      
      If InStrRev($_ShortcutName, '.url') And $_IconPath
        $_Index = InStrRev($_IconPath, ',')
        If $_Index = 0
          $_IconIndex = 0
        Else
          $_IconIndex = split($_IconPath, ',')[1]
          $_IconPath = split($_IconPath, ',')[0]
        EndIf
        $_Rc = WriteProfileString($_ShortcutName, 'InternetShortcut', 'IconFile', $_IconPath)
        $_Rc = WriteProfileString($_ShortcutName, 'InternetShortcut', 'IconIndex', $_IconIndex)
      EndIf
      
      $_Shortcut = 0
      $wshShortcut = 1
      Exit 0
    Else
      Exit @ERROR
    EndIf 
  Else
    Exit @ERROR
  EndIf 
 
EndFunction