Task Scheduler: How to automatically synchronize my USB flash drive?

Anonymous
2009-12-19T15:42:25+00:00

I once knew the right settings to automatically synchronize my USB flash drive with the files on my computer, but I forgot. I am using a synchronization and back-up program called ´SyncBack´. It works fine, but I want it to automatically run each time I put in my USB flash drive.

I know how to use the task scheduler,

I know what to fill in under ´Actions´ (namely, I have to tell the Scheduler which program to run with which command)

But I don´t know what to fill in under ´Triggers´. I want it to run each time i put in a designated USB drive. In my memory it had something to do with ´event id´...and I had to fill in the name of my USB drive.

Can anyone solve this one?

Windows for home | Previous Windows versions | Apps

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2009-12-19T17:09:16+00:00

Hi,

Be sure you logon as ADMIN

Windows Vista Task Scheduler

http://technet.microsoft.com/en-us/appcompat/aa906020.aspx

Task Scheduler 2.0

http://msdn.microsoft.com/en-us/library/bb756979.aspx

How to Create a Task in Vista Task Scheduler

http://www.vistax64.com/tutorials/132903-task-scheduler-create-task.html

Create custom event triggers in Vista Task Scheduler

http://www.techrepublic.com/blog/windows-and-office/create-custom-event-triggers-in-vista-task-scheduler/

Put the ThumbDrive in, copy a few files to it, then Safely Remove and check the event viewer for the Event ID if needed.

Look in the Event Viewer. This free utility makes it easy to check though you might need to also check with the Windows Event Viewer.

http://www.computerperformance.co.uk/vista/vista\_event\_viewer.htm

Hope this helps.


Rob Brown - Microsoft MVP <- profile - Windows and Devices for IT : Bicycle - Mark Twain said it right.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

17 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-01-10T04:50:23+00:00

    I had the same question as you, and worked out something with powershell (windows built-in scripting) using techniques from the Scripting Guy Blog here and here. The script runs continuously as a background process, which you can start at system logon with task scheduler. The script will be notified whenever a new drive is plugged and then do something (here you configure the script rather than the task). Since it is basically paused while waiting for the next plugged drive, you should not find it takes up much resources. Here I go:

    1. Start Powershell ISE, which can be found in your start menu under Accessories/Windows Powershell.
    2. Copy paste the following into Powershell.

    #Requires -version 2.0

    Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange

    write-host (get-date -format s) " Beginning script..."

    do{

    $newEvent = Wait-Event -SourceIdentifier volumeChange

    $eventType = $newEvent.SourceEventArgs.NewEvent.EventType

    $eventTypeName = switch($eventType)

    {

    1 {"Configuration changed"}

    2 {"Device arrival"}

    3 {"Device removal"}

    4 {"docking"}

    }

    write-host (get-date -format s) " Event detected = " $eventTypeName

    if ($eventType -eq 2)

    {

    $driveLetter = $newEvent.SourceEventArgs.NewEvent.DriveName

    $driveLabel = ([wmi]"Win32_LogicalDisk='$driveLetter'").VolumeName

    write-host (get-date -format s) " Drive name = " $driveLetter

    write-host (get-date -format s) " Drive label = " $driveLabel

    Execute process if drive matches specified condition(s)

    if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')

    {

    write-host (get-date -format s) " Starting task in 3 seconds..."

    start-sleep -seconds 3

    start-process "Z:\sync.bat"

    }

    }

    Remove-Event -SourceIdentifier volumeChange

    } while (1-eq1) #Loop until next event

    Unregister-Event -SourceIdentifier volumeChange

    1. You need to modify the script above to tell the script what drive to look for, and what to execute. The two lines to change are:
    • if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')

    My usb hard drive named 'Mirror' is set as the Z: drive. You could just use if ($driveLabel -eq 'MyDiskLabel') if you didn't care about the letter.

    • start-process "Z:\sync.bat"

    Path of whatever task you want to do. In my example, I have created a batch file on my USB drive which start 3-4 backup tasks command lines (which SyncBack support if I'm not mistaken)

    1. When you're done, save your script somewhere (extension .ps1), then go create a task in Task Scheduler to have your script run in background. Mine looks like this:
    • Trigger: At log on
    • Action: Start a program
    • Program/script: powershell
    • Add arguments: -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"
    1. Voilà!
    2. Extra stuff:

    If you want your script window to be hidden, use these arguments:

    • Add arguments: -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"

    If you want to output the script messages into a log file (that gets overwritten everytime the script starts, i.e. at log on), use the following task action:

    • Program/script: cmd
    • Add arguments: /c powershell -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1" > "D:\Stuff\script log.txt"

    Anytime you want to end the running hidden script, you can end the "Powershell" process in Task Manager.

    The only downside is that nothing will run when you boot your computer with the drive already plugged in. (The script could be changed to perform a first check initially though, but I've had enough for today!)

    Was this answer helpful?

    8 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2010-05-20T13:37:49+00:00

    Note that the USB insertion event is a little hard to find. I poked around a bit, and found them located in "Event Viewer/Applications and Services Logs/Microsoft/Windows/DriverFrameworks-UserMode/Operational". Try clearing the log first (just to make it easier to find the event you want), then insert the USB flash drive. Refresh the log, and a bunch of events should show up. I picked the top most event (i.e. the most recent), and assigned the task to that (make sure the event description looks like it has something specific to the particular USB drive you inserted).

    To assign the task correctly, right click the event and choose "Attach task to this event..." You should be good from there.

    I'm using Windows 7.

    Was this answer helpful?

    5 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2012-02-06T21:52:26+00:00

    I had the same question as you, and worked out something with powershell (windows built-in scripting) using techniques from the Scripting Guy Blog here and here. The script runs continuously as a background process, which you can start at system logon with task scheduler. The script will be notified whenever a new drive is plugged and then do something (here you configure the script rather than the task). Since it is basically paused while waiting for the next plugged drive, you should not find it takes up much resources. Here I go:

    1. Start Powershell ISE, which can be found in your start menu under Accessories/Windows Powershell.
    2. Copy paste the following into Powershell.

    #Requires -version 2.0

    Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange

    write-host (get-date -format s) " Beginning script..."

    do{

    $newEvent = Wait-Event -SourceIdentifier volumeChange

    $eventType = $newEvent.SourceEventArgs.NewEvent.EventType

    $eventTypeName = switch($eventType)

    {

    1 {"Configuration changed"}

    2 {"Device arrival"}

    3 {"Device removal"}

    4 {"docking"}

    }

    write-host (get-date -format s) " Event detected = " $eventTypeName

    if ($eventType -eq 2)

    {

    $driveLetter = $newEvent.SourceEventArgs.NewEvent.DriveName

    $driveLabel = ([wmi]"Win32_LogicalDisk='$driveLetter'").VolumeName

    write-host (get-date -format s) " Drive name = " $driveLetter

    write-host (get-date -format s) " Drive label = " $driveLabel

    Execute process if drive matches specified condition(s)

    if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')

    {

    write-host (get-date -format s) " Starting task in 3 seconds..."

    start-sleep -seconds 3

    start-process "Z:\sync.bat"

    }

    }

    Remove-Event -SourceIdentifier volumeChange

    } while (1-eq1) #Loop until next event

    Unregister-Event -SourceIdentifier volumeChange

    1. You need to modify the script above to tell the script what drive to look for, and what to execute. The two lines to change are:
    • if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')

    My usb hard drive named 'Mirror' is set as the Z: drive. You could just use if ($driveLabel -eq 'MyDiskLabel') if you didn't care about the letter.

    • start-process "Z:\sync.bat"

    Path of whatever task you want to do. In my example, I have created a batch file on my USB drive which start 3-4 backup tasks command lines (which SyncBack support if I'm not mistaken)

    1. When you're done, save your script somewhere (extension .ps1), then go create a task in Task Scheduler to have your script run in background. Mine looks like this:
    • Trigger: At log on
    • Action: Start a program
    • Program/script: powershell
    • Add arguments: -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"
    1. Voilà!
    2. Extra stuff:

    If you want your script window to be hidden, use these arguments:

    • Add arguments: -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"

    If you want to output the script messages into a log file (that gets overwritten everytime the script starts, i.e. at log on), use the following task action:

    • Program/script: cmd
    • Add arguments: /c powershell -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1" > "D:\Stuff\script log.txt"

    Anytime you want to end the running hidden script, you can end the "Powershell" process in Task Manager.

    The only downside is that nothing will run when you boot your computer with the drive already plugged in. (The script could be changed to perform a first check initially though, but I've had enough for today!)

    Okay I'm pretty new to all this scripting, in fact today was the first time I tried it, all worked fine managed it get it all working perfectly in conjunction with SyncToy. There's one problem when i start up and log on theres a console window that comes up and I need to close it, the WindowStyle Hidden doesn't seem to be working. Ive even tried Hstart but I do not understand it enough.

    Do you have any suggestions?

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2010-05-16T05:52:13+00:00

    I had the same question as you, and worked out something with powershell (windows built-in scripting) using techniques from the Scripting Guy Blog here and here . The script runs continuously as a background process, which you can start at system logon with task scheduler. The script will be notified whenever a new drive is plugged and then do something (here you configure the script rather than the task). Since it is basically paused while waiting for the next plugged drive, you should not find it takes up much resources. Here I go:

    1. Start Powershell ISE, which can be found in your start menu under Accessories/Windows Powershell.
    2. Copy paste the following into Powershell.

    #Requires -version 2.0

    Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange

    write-host (get-date -format s) " Beginning script..."

    do{

    $newEvent = Wait-Event -SourceIdentifier volumeChange

    $eventType = $newEvent.SourceEventArgs.NewEvent.EventType

    $eventTypeName = switch($eventType)

    {

    1 {"Configuration changed"}

    2 {"Device arrival"}

    3 {"Device removal"}

    4 {"docking"}

    }

    write-host (get-date -format s) " Event detected = " $eventTypeName

    if ($eventType -eq 2)

    {

    $driveLetter = $newEvent.SourceEventArgs.NewEvent.DriveName

    $driveLabel = ([wmi]"Win32_LogicalDisk='$driveLetter'").VolumeName

    write-host (get-date -format s) " Drive name = " $driveLetter

    write-host (get-date -format s) " Drive label = " $driveLabel

    Execute process if drive matches specified condition(s)

    if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')

    {

    write-host (get-date -format s) " Starting task in 3 seconds..."

    start-sleep -seconds 3

    start-process "Z:\sync.bat"

    }

    }

    Remove-Event -SourceIdentifier volumeChange

    } while (1-eq1) #Loop until next event

    Unregister-Event -SourceIdentifier volumeChange

    1. You need to modify the script above to tell the script what drive to look for, and what to execute. The two lines to change are:
    • if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')

    My usb hard drive named 'Mirror' is set as the Z: drive. You could just use if ($driveLabel -eq 'MyDiskLabel') if you didn't care about the letter.

    • start-process "Z:\sync.bat"

    Path of whatever task you want to do. In my example, I have created a batch file on my USB drive which start 3-4 backup tasks command lines (which SyncBack support if I'm not mistaken)

    1. When you're done, save your script somewhere (extension .ps1), then go create a task in Task Scheduler to have your script run in background. Mine looks like this:
    • Trigger: At log on
    • Action: Start a program
    • Program/script: powershell
    • Add arguments: -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"
    1. Voilà!
    2. Extra stuff:

    If you want your script window to be hidden, use these arguments:

    • Add arguments: -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"

    If you want to output the script messages into a log file (that gets overwritten everytime the script starts, i.e. at log on), use the following task action:

    • Program/script: cmd
    • Add arguments: /c powershell -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1" > "D:\Stuff\script log.txt"

    Anytime you want to end the running hidden script, you can end the "Powershell" process in Task Manager.

    The only downside is that nothing will run when you boot your computer with the drive already plugged in. (The script could be changed to perform a first check initially though, but I've had enough for today!)

    nice,

    but this script work perfectly on windows 7 and not working on windows xp

    i need that script or any another script work with windows xp

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments