Detecting when a drive is disconnected

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
softwareeater
Posts: 42
Joined: 31 Aug 2015, 11:33

Detecting when a drive is disconnected

07 May 2021, 16:19

Hey all, I'm trying to make a script that will confirm for me if one of my network drives is connected or not. This was my first attempt:

Code: Select all

IsNetworkConnected()
{
try
	{
	FileRead, filecheck, \\mydrive\test.txt ;(I've also tried FileCheck() with the same results)
	return "yes"
	}
catch
	{
	msgbox, hmm
	return
	}
}
[Mod edit: [code][/code] tags added.]

Things seem to work when the drive is connected. However, when it's disconnected, instead of reaching the catch (or making it through FileRead and returning "yes") the script locks up completely. I thought maybe I could make do, by putting the FileRead in a second script, launching it from my main script, then killing the second script if it takes too long. But I can't seem to kill it. Here's what I tried:

Code: Select all

SetTitleMatchMode,2
DetectHiddenWindows,on
WinClose,\filecheck.ahk - Autohotkey

So. Does anyone know a better way to check if a drive/file can be accessed, or a better way to kill a frozen script?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, septrinus and 292 guests