2

I have a batch file that makes a backup of a project folder on my USB stick to a drive on my pc:

@echo off

rem This makes some funky colours

set /a rand1=%random% %% 16
set /a rand2=%random% %% 16
set HEX=0123456789ABCDEF
call set hexcolors=%%HEX:~%rand1%,1%%%%HEX:~%rand2%,1%%
color %hexcolors%

rem This is the xcopy script

echo Initiating copy...    
REM copy documents    
xcopy "h:\Projects\*.*" e:\Backup\ /s /r /d /y /i     
echo %DATE% %TIME% > e:\Backup\xcopy.log    
echo Backup Complete    

echo Initiating exit...    
timeout /t 3    

I want this batch file to run every time my USB stick is inserted. I found on the internet that event 2003 and 4688 are triggered when a usb external disk is plugged in.

However when I scheduled a task to run the program 'backup.bat' from '\' on event 2003 and again with 4688 - on inserting a USB stick, the batch file doesn't run. I think this is something wrong with the event trigger as when i run the task in task scheduler it runs the batch file.

The event event log

0

1 Answer 1

1

It looks like your task is configured correctly. However the event isn't being logged when you insert a USB device, so there's nothing to trigger the scheduled task.

Not all event logs are enabled by default in Windows. You can check for this, and enable the event log your task is referencing, as follows:

  1. Open Event Viewer
  2. Navigate in the left pane to the event log referenced by your task and expand it
  3. Still in the left pane, right-click on the appropriate log (usually Operational) and choose Enable

Now connect your flash drive and see if the event is logged and your task triggered.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .