udfShortCutCopy
bln udfShortCutCopy (str, str)
;==========================================================================================================================================------------------------------------------------------------------------------------------------------------------------------------------
; How to copy an existing shortcut ".lnk" file to another target folder?
;
; This is an updated WinBatch script, now using colon concatenation.
;
; (c) Detlev Dalitz.20030701.20091225.
;==========================================================================================================================================------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfShortcutCopy (strShortcutSourceFilename, strShortcutTargetFilename)
strInfo = ShortCutInfo (strShortcutSourceFilename)
strLinkTarget   = ItemExtract (1, strInfo, @TAB)
strParams       = ItemExtract (2, strInfo, @TAB)
strFolderStart  = ItemExtract (3, strInfo, @TAB)
intShowMode     = ItemExtract (4, strInfo, @TAB)
strDescription  = ItemExtract (5, strInfo, @TAB)
strHotkey       = ItemExtract (6, strInfo, @TAB)
strIconFilename = ItemExtract (7, strInfo, @TAB)
intIconIndex    = ItemExtract (8, strInfo, @TAB)
intResult = FileExist (strShortcutTargetFilename)
If intResult == 2 Then Return @FALSE ; Cannot access existing shortcut file because file is locked by another application.
If intResult == 1
   FileAttrSet (strShortcutTargetFilename, "rash") ; Force delete existing shortcut file.
   blnResult = FileDelete (strShortcutTargetFilename)
EndIf
blnResultMake = ShortCutMake (strShortcutTargetFilename, strLinkTarget, strParams, strFolderStart, intShowMode)
blnResultExtra = ShortCutExtra (strShortcutTargetFilename, strDescription, strHotkey, strIconFilename, intIconIndex)
Return blnResultMake && blnResultExtra
;..........................................................................................................................................
; This Function "udfShortCutCopy" returns a boolean value,
; which indicates if the shortcut manipulation has been done successfully or not.
;
; This Function creates a copy of an existing shortcut ".lnk"-file
; as defined in parameter "strShortcutSourceFilename" into another target folder.
;
; Note:
; If a target shortcut ".lnk"-file with the same name
; as defined in parameter "strShortcutTargetFilename" already exists,
; it will be deleted, if possible, without permission!
;
; Detlev Dalitz.20030701.20091225.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

; Test.

; Remember start folder.
strFolderStart = DirGet ()

; Prepare testcase.
; Create shortcut on user desktop.
strFolderDesktop = ShortCutDir ("Desktop", 0, 1)
blnResult = DirChange (strFolderDesktop)

strLinkFilename = "Testcase." : StrInsert (StrReplace (TimeYmdHms (), ":", ""), ".", "", 9) : ".lnk"
strLinkTarget   = FileLocate ("Explorer.exe")
strParams       = "/e, /select, C:\"
strFolderStart  = "C:\"
intShowMode     = @NORMAL
intShortcutType = 0 ; Normal shortcut (default)
strDescription  = "*** Testcase ShortCutCopy ***"
strHotkey       = "!^+a" ; Just for the test, don't know if this works.
strIconFilename = FileLocate ("SHELL32.DLL")
intIconIndex    = 41

intResult = ShortCutMake (strLinkFilename, strLinkTarget, strParams, strFolderStart, intShowMode, intShortcutType)
intResult = ShortCutExtra (strLinkFilename, strDescription, strHotkey, strIconFilename, intIconIndex)

; Prepare and perform ShortCutCopy.
; In this example we use the user temp folder as the target folder.
strFolderTemp = ShortCutDir ("Local Settings", 0, 1) : "Temp\"
strShortcutFilename = "Testcase - This is a shortcut copy"
strShortcutTarget = strFolderTemp : strShortcutFilename : ".lnk"
strShortcutSource = strLinkFilename

; Create a copy in the target folder.
blnResult = udfShortcutCopy (strShortcutSource, strShortcutTarget)

If blnResult
   ; Check both shortcut properties.
   blnResult = ShellExecute (strShortcutSource, "", "", @NORMAL, "properties")
   blnResult = ShellExecute (strShortcutTarget, "", "", @NORMAL, "properties")
   blnResult = WinWaitClose ("~" : strShortcutFilename)
Else
   Message ("ShortCutCopy not successful", "Source:" : @LF : strShortcutSource : @LF : @LF : "Target:" : @LF: strShortcutTarget)
EndIf

; Cleanup.
intResult = FileDelete (strShortcutSource)
intResult = FileDelete (strShortcutTarget)

; Back to start folder.
blnResult = DirChange (strFolderStart)

Exit
;==========================================================================================================================================------------------------------------------------------------------------------------------------------------------------------------------