1) Open an external drive (USB drive or key, for example). Create or copy an MS Office file on this drive and open it (just to make sure this file is registered in the Recent items).
2) Open Recent items (C:\Users\[User Name]\AppData\Roaming\Microsoft\Windows\Recent Items) to confirm that the file and the folder containing this file on the removable drive are the most recent items in the list.
3) Run the script below. The 4 most recent items shortcuts will be resolved. Everything will run fine since the external drive is still available.
4) Eject the external drive, using the External device tray icon.
5) Run again the script below. Now (this is the tricky part), the script below will follow one of these scenarios:
5.1) The FileGetShortcut will resolve the shortcut event if the drive is unavailable (no errorlevel, no error thrown for the Try/Catch commands). This is what happens on my PC #1. I like it
5.2) The FileGetShortcut will throw an error and the Try/Catch commands will NOT catch the error. Instead, Windows will display an error message like this "There is no disk in the drive. Please insert a disk into drive \Device\Harddisk\XYZ.". This is what happens on my PC #2. I don't like it
PCs #1 and #2 are both Win 7 64-bit, running the same AHK executable (1.1.14.03, compiled version or not). Tested with the same removable drive on each PC.
My questions:
A) Can you reproduce the scenario 5.2?
b) For those having so much "Inside Windows" knowledge than me, in what direction would you search for the difference between PCs #1 and #2 that would explain these two behaviors?
Thanks for your input,
Jean
Code: Select all
; Find the recent items folders in Windows XP or 7/8/8.1
if (A_OSVersion = "WIN_XP")
{
strRecentsFolder := SubStr(A_AppData, 1, InStr(A_AppData, "\", , 0) - 1) . "\Recent"
if !FileExist(strRecentsFolder)
strRecentsFolder := SubStr(A_AppData, 1, InStr(A_AppData, "\", , 0) - 1) . "\My Recent Documents"
}
else
strRecentsFolder := A_AppData . "\Microsoft\Windows\Recent"
strDirList := ""
; Sort recent items chronologically
Loop, %strRecentsFolder%\*.*
strDirList := strDirList . A_LoopFileTimeModified . "`t`" . A_LoopFileFullPath . "`n"
Sort, strDirList, R
Loop, parse, strDirList, `n
{
if !StrLen(A_LoopField) ; last line is empty
continue
arrTargetFullName := StrSplit(A_LoopField, A_Tab)
strTargetFullName := arrTargetFullName[2]
MsgBox, % "Will resolve shortcut #" . A_Index . ":`n" . strTargetFullName
try FileGetShortcut, %strTargetFullName%, strOutTarget
catch
{
MsgBox, % "Error CATCHED in FileGetShortcut."
continue
}
if (errorlevel) ; hidden or system files (like desktop.ini) returns an error
{
MsgBox, % "Errorlevel: " . errorlevel
continue
}
MsgBox, % "Resolved file name is for #" . A_Index . " is:`n" . strOutTarget
; here, in my full script, I check if the resolved file exists and do what I have to do if it exists
if (A_Index > 3)
break
}
return