I'd like to be informed (either immediately or with a delay of at max 10 minutes) if drive H: is not available/connected.
ChatGPT said I should schedule this .bat file in Task scheduler, but I have no clue if this is safe or has issues:
@echo off
set DriveLetter=H:
set FlagFile=%TEMP%\DriveNotConnected.flag
if not exist %DriveLetter%\ (
if not exist %FlagFile% (
msg * "Drive %DriveLetter% not connected!"
echo. > %FlagFile%
)
) else (
del %FlagFile% 2>nul
)
Would someone care to tell me if the the above ChatGPT-code is bug/issue-free and could be used / are there any suggesitons for improvement, or other ways to achieve this?
The device is needed by various backup programs, but it's not always attached. I can't rely on it being attached so I'd like to be informed. Could also be a network drive that could lose connectivity due to WiFi issues, for example, I guess. Here it's a USB flash drive.
To be honest, there's an underlying issue with Parallels and possibly (!!) NTFS for Mac (Paragon) that I'm in the process of troubleshooting (NTFS-formatted USB drive won't attach the the Windows VM automatically / is unreliable), but then again there are also more reasons than that that the drive might not be attached to the Windows VM so it's always good to get a notification. The backup programs have their own (partly weird or not helpful) ways of informing about unavailable drives, so I just wanted a simple and reliable solution. Generally speaking it would not hurt if a certain backup task will be triggered once it's attached, but that's not a must.
Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /c C:\Admin\Backup\Drive_Check\Drive_Check.bat", 0
Set objShell = Nothing
C:\Admin\Backup\Drive_Check\Drive_Check.bat
@echo off
set DriveLetter=H:
set FlagFile=C:\Admin\Backup\Drive_Check\DriveNotConnected.flag
set "nircmdPath=C:\Admin\Backup\Drive_Check\nircmd.exe"
if not exist %DriveLetter%\ (
if not exist %FlagFile% (
"%nircmdPath%" infobox "Please connect flash drive!" "Drive Checker" 0 0
echo. > %FlagFile%
)
) else (
if exist %FlagFile% (
del %FlagFile%
)
)