If you are like me, you often work with a portable computer and sleep your computer between commutes from the office, home, and road. If you wake up your computer on a different network than the one you were on previously, you might be in for quite the annoyance if you had bunch of Explorer windows with
UNC paths open. Suddenly those paths are not found and potentially dozens of "Network Error Windows cannot access \\serverfoo\some\path\bar" messages. Of course, they cannot be accessed, that network is no longer available. Clicking Cancel on each dialog is annoying. This is where
AutoHotKey can step in.
This nifty program allows you to script all sorts of "macros" to automate various tasks on your computer. In many ways its similar to
AppleScript but more powerful. You can create shortcuts, remap keys, or in this case, eliminate pesky dialog boxes.
In this script, we are going to create a persistent script, one that will stay running and continue to refire the timer using the interval we specify:
#Persistent
SetTimer, CloseNetworkErrorDialog, 20000
return
CloseNetworkErrorDialog:
SetTitleMatchMode, 2
WinGet, id, list, Network Error
Loop, %id%
{
this_id := id%A_Index%
WinGetTitle, this_title, ahk_id %this_id%
PostMessage, 0x112, 0xF060,,, %this_title%
}
Return
As you can see, this is a really simple script that has a function named CloseNetworkErrorDialog that is called every 20 seconds. CloseNetworkErrorDialog loops through the open windows whose title contain the phrase "Network Error", gets the exact title of the window, and sends it a
Close Window command. You can read more about creating AutoHotKey scripts
here.
Peace at last and it only took 5 minutes to write.