It then creates a shortcut to a non-existent file (also in the script directory). The target file and run directory references in the shortcut are correct even though the file doesn't exist.
It then creates a shortcut to a non-existent file on a non-existent disk. The run directory reference is still OK, but the target file reference now has all the blanks replaced with underscores! That is NOT what I would expect. Testing confirms that whenever the target is on a non-existent disk, the target reference gets munged.
Running AHK 1.1.25.01 (64-bit Unicode) on Windows 7 (64-bit). Note: Norton complains vociferously about any attempt to install 1.1.26.01...
Code: Select all
;
; SCRIPT: SCTest.ahk
;
; DESCRIPTION:
; Shortcut Test...
;
#NoEnv
#NoTrayIcon
#SingleInstance off
SendMode, Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
StringCaseSense, Off
; Create a file...
targetfile := A_ScriptDir . "\SC Target.txt"
dummytext := "Just some dummy text`n"
FileAppend, %dummytext%, %targetfile%
; Create a good shortcut to the file...
linkfile := A_ScriptDir . "\SC Good Link.lnk"
FileCreateShortcut, %targetfile%, %linkfile%, %A_ScriptDir%,,,,,,
; Get the shortcut...
target := ""
dir := ""
FileGetShortcut, %linkfile%, target, dir,,,,,
msg := "linkfile=" . linkfile . "`n`ntarget=" . target . "`n`ndir=" . dir
MsgBox, 0x1010, SC Test..., %msg%
; Create another shortcut to a non-existent file...
targetfile := A_ScriptDir . "\SC Missing File.txt"
linkfile := A_ScriptDir . "\SC Missing File Link.lnk"
FileCreateShortcut, %targetfile%, %linkfile%, %A_ScriptDir%,,,,,,
; Get the shortcut...
target := ""
dir := ""
FileGetShortcut, %linkfile%, target, dir,,,,,
msg := "linkfile=" . linkfile . "`n`ntarget=" . target . "`n`ndir=" . dir
MsgBox, 0x1010, SC Test..., %msg%
; Create a shortcut to a non-existent disk...
targetfile := "A:\Missing Disk\SC Missing File.txt"
linkfile := A_ScriptDir . "\SC Missing Disk Link.lnk"
dir := "A:\Missing Disk"
FileCreateShortcut, %targetfile%, %linkfile%, %dir%,,,,,,
; Get the shortcut...
target := ""
dir := ""
FileGetShortcut, %linkfile%, target, dir,,,,,
msg := "linkfile=" . linkfile . "`n`ntarget=" . target . "`n`ndir=" . dir
MsgBox, 0x1010, SC Test..., %msg%
Return