0

I would like to have the Windows Task Scheduler to run a program when I plug in my external hard disk drive. I know how to set the time and boot schedules but for event schedules I have no idea.

Is it too much trouble to run applications by events? I can just use a shortcut instead or make the event happen every 30 mins or so to run the job. (Usually I have it attached for 30 mins + enough time for the job to finish.)

2
  • You could create a scheduled task to run every 30 min that uses a VBscript to check for your plugged in disk. I'm not putting this as an answer since I don't have time to write the script :)(leaving work!)
    – Jeff F.
    Sep 15, 2010 at 21:45
  • The app checks the path before doing anything so i dont need that. I decided every 30mins is 'soon enough'
    – user3109
    Sep 16, 2010 at 15:22

2 Answers 2

1

I am doing this also,

Here an XML export of my task. You can import it and customize it for your use case:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2013-03-29T10:22:52.2396539</Date>
    <Author>XXXXXXX</Author>
    <Description>TODO: run rsyn on this trigger to backup directories!!</Description>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-DriverFrameworks-UserMode/Operational"&gt;&lt;Select Path="Microsoft-Windows-DriverFrameworks-UserMode/Operational"&gt;*[System[Provider[@Name='Microsoft-Windows-DriverFrameworks-UserMode'] and EventID=2101]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>XXXXXX</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <ShowMessage>
      <Title>Yes 2</Title>
      <Body>USB disk ok</Body>
    </ShowMessage>
  </Actions>
</Task>

This file shows a popup message when a USB key is inserted.

You may have to customize it.

Regards

0

Check a previous answer I have given on this site to add an event handler using a script with Powershell (built-in Windows 7) that is started at logon using Task Scheduler.

You must log in to answer this question.