Task Scheduler action on drive mount

1

I have a drive that uses TrueCrypt. I have a program installed that uses that drive. If I start the program and the TrueCrypt drive hasn't been mounted, it gets very upset. So, I would like to have a task in the Task Scheduler that starts the program when the drive becomes accessible.

How would I set up the trigger for such a task? Perhaps the trigger would be something like "as soon as D:\ becomes available" or something like that.

Jordan

Posted 2014-02-07T20:51:36.600

Reputation: 177

Answers

2

You can do it using WMI. Here's a quick and dirty example taken from here: WMI Tasks: Disks and File Systems

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" _
   & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService. _
   ExecNotificationQuery( _
     "Select * from Win32_VolumeChangeEvent")
Set objShell = WScript.CreateObject("WScript.Shell")

Do
   Set objLatestEvent = colMonitoredEvents.NextEvent
   If objLatestEvent.DriveName = "F:" Then
      objShell.Run("""%windir%\system32\notepad.exe""")     
   End If
Loop

Walter

Posted 2014-02-07T20:51:36.600

Reputation: 136

1

You could always write up a batch script to mount the drive, start the program you want, and dismount on close, and use a shortcut in place of all shortcuts for the shortcuts for the program you have installed that uses that drive.

Matej Voboril

Posted 2014-02-07T20:51:36.600

Reputation: 136

This was definitely the simplest way to do it, thanks for the suggestion. This is what I went with, but doesn't specifically address the question so I accepted the other one. – Jordan – 2014-02-08T07:10:52.040

I'm just glad you found a good solution :-) – Matej Voboril – 2014-02-10T19:40:08.567