;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       AddNetShortcut() / ListNetShortcut 
;; 
;;ACTION         Adds a shortcut to Network Neighborhood / Lists existing shortcuts 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2014/10/10 
;; 
;;HISTORY        1.0  - 2014/10/10 - Initial Release 
;; 
;;SYNTAX         AddNetShortcut(Name, Path) / ListNetworkShortcut() 
;; 
;;PARAMETERS     Name - REQUIRED - String 
;;               - The "friendly" name of the shortcut 
;; 
;;               Path - REQUIRED - The UNC Path being mapped to the shortcut 
;; 
;;REMARKS        AddNetworkShortcut creates a new shortcut in the Network Neighborhood. 
;; 
;;               ListNetworkShortcut is used to list the existing shortcuts. 
;; 
;;RETURNS        AddNetworkShortcut: 1=Success, 0=Fail (check exit code) 
;; 
;;               ListNetworkShortcut: Returns an array of existing shortcuts in the  
;;               network neighborhood. Each array element defines the full path to 
;;               the shortcut and the target, delimited by a semicolon. 
;; 
;;DEPENDENCIES   WSH 
;; 
;;TESTED WITH    W2K3, W2K8, W2K12 
;; 
;;EXAMPLES       If AddNetworkShortcut('Dept Data', '\\server\DeptData') 
;;                 'Shortcut created!' 
;;               EndIf 
; 
; create a network shortcut with a specific name and path  
Function AddNetShortcut($_Name, $_Path)
 
  Dim $_NetHood					; Constant identifier for NetHood path 
  Dim $_oWshShell, $_oShell			; Object pointers for shell 
  Dim $_oFolder, $_oFolderItem			; Object pointers for folder 
  Dim $_sNetHood				; String containing NetHood path value 
  Dim $_oShortcut				; Shortcut object pointer 
 
  $_NetHood = &13
  $_oWshShell = CreateObject("wscript.shell")
  $_oShell = CreateObject("Shell.Application")
 
  $_oFolder = $_oShell.Namespace($_NetHood)
  $_oFolderItem = $_oFolder.Self
  $_sNetHood = $_oFolderItem.Path
 
 
  If Right($_Name, 4) <> '.lnk'
    $_Name =$_Name + '.lnk'
  EndIf
  $_sNetHood = $_sNetHood + '/' + $_Name
 
  $_oShortcut = $_oWshShell.CreateShortcut($_sNetHood)
 
  $_oShortcut.TargetPath = $_Path
  $_oShortcut.Save
 
  $AddNetShortcut = Not @ERROR
  Exit @ERROR
 
EndFunction
 
 
; Return an array of network shortcuts 
Function ListNetShortcut()
 
  Dim $_					; Temp var 
  Dim $_NetHood					; Constant identifier for NetHood path 
  Dim $_oWshShell, $_oShell			; Object pointers for shell 
  Dim $_oFolder, $_oFolderItem			; Object pointers for folder 
  Dim $_oShortcut				; Shortcut object pointer 
  Dim $_sNetHood				; String containing NetHood path value 
  Dim $_I					; Index pointer 
  Dim $_aFiles					; array of matching files 
  Dim $_FqFn
 
  $_NetHood = &13
  $_I = -1
 
  $_oWshShell = CreateObject("wscript.shell")
  $_oShell = CreateObject("Shell.Application")
 
  $_oFolder = $_oShell.Namespace($_NetHood)
  $_oFolderItem = $_oFolder.Self
  $_sNetHood = $_oFolderItem.Path
 
  $_ = Dir($_sNetHood + '\*.lnk')
  While Not @ERROR
    $_FqFn = $_sNetHood + '\' + $_
    $_oShortcut = $_oWshShell.CreateShortcut($_FqFn)
    $_I = $_I + 1
    ReDim Preserve $_aFiles[$_I]
    $_aFiles[$_I] = $_FqFn + ';' + $_oShortcut.targetpath
    $_ = Dir()
  Loop
 
  $ListNetShortcut = $_aFiles
  Exit 0
 
EndFunction