Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Mr.Humble

Automatic copy from USB drive to PC on plug-in

7 hours ago, nerdv2 said:

Are you sure that autoplay and autorun are enabled?
Enabling autorun/autoplay is bad idea security-wise.

You could force it to be enabled via group policy.
https://www.techrepublic.com/article/how-to-disable-autoplay-and-autorun-in-windows-10/

If you have time, prefer to detect the device dynamically with C# using InteropServices.
https://www.codeguru.com/columns/dotnet/detecting-usb-devices-using-c.html
And you can execute the batch script or even customize it yourself.

It probably could be done if I knew any programming at all.

 

I found a solution though: I looked up the event ID and source when the external SSD gets plugged in, then I used that as a trigger in Event planner to start the copy "script" stored on the external SSD.

 

However then I was running into an issue where if I plug in another external drive, it starts the copy if the external SSD is still connected. I solved that by making a more detailed filter for the trigger event as shown:

<QueryList>
  <Query Id="0" Path="Microsoft-Windows-Ntfs/Operational">
    <Select Path="System">*[System[Provider[@Name='Microsoft-Windows-Ntfs'] and (Level=4 or Level=0) and (EventID=98) and TimeCreated[timediff(@SystemTime) <= 10000]]]
    
    and
    
    *[EventData[Data[@Name='DriveName'] and (Data='W:')]]</Select>
  </Query>
</QueryList>

I found out how to do that here.

 

This way the event "Import laptop backup" only triggers when the external SSD is inserted, and it ignores any other (NTFS) external drives.

Recommended Posts

Posted · Original PosterOP

Hi,

 

I need some help with my backup.

 

My situation: I have a laptop and a desktop with a large hard drive for storage. I periodically backup the laptop to a portable SSD using Acronis and differential backup.
 

I want to have an automatic solution to copying that backup to my desktop. I know this can be done with a robocopy script in a .bat file and an autorun, but I'm not sure how to make it work when I plug in the drive.

 

I would prefer to avoid a solution requiring other software.

 

I tried to modify a solution from this thread but I don't know how to make it start on it's own when I connect the SSD to the desktop.

https://superuser.com/questions/22766/how-can-i-automatically-copy-files-to-a-usb-drive-when-i-connect-it-to-my-comput

 

these are the "scripts" I use:

 

the .bat file:

@echo off
cls
echo waiting
goto check

Change the STUFF TO COPY location to the folder that you want 
everything inside to be send to the usb's, and change the 3 instances of 
G: to whatever drive letter that the USB uses.
Good Luck!

:start
set choice=
robocopy "W:\BACKUP\VOJTA-NOTEBOOK" "D:\BACKUP\VOJTA-NOTEBOOK" /E /XA:SH /R:3 /NP /V
echo Waiting for removal
goto wait

:check
timeout /t 1 /nobreak >nul
if exist "W:" (goto start) else goto check

:wait
timeout /t 1 /nobreak >nul
if exist "W:" (goto wait) else (
echo removed
echo waiting
goto check
)

the autorun:

[autorun]
 ;Open=backup_copy_ntb.bat
 ShellExecute=backup_copy_ntb.bat
 UseAutoPlay=1

Does anyone have any suggestion please?


Quote and/or tag people using @ otherwise they don't get notified of your response!

 

The HUMBLE Computer:

AMD Ryzen 7 3700X • Noctua NH-U12A • ASUS STRIX X570-F • Corsair Vengeance LPX 32GB (2x16GB) DDR4 3200MHz CL16 • GIGABYTE Nvidia GTX1080 G1 • FRACTAL DESIGN Define C w/ blue Meshify C front • Corsair RM750x (2018) • OS: Kingston KC2000 1TB GAMES: Intel 660p 1TB DATA: Seagate Desktop 2TB • Acer Predator X34P 34" 3440x1440p 120 Hz IPS curved Ultrawide • Corsair STRAFE RGB Cherry MX Brown • Logitech G502 HERO / Logitech MX Master 3

 

Notebook:  HP Spectre x360 13" late 2018

Core i7 8550U • 16GB DDR3 RAM • 512GB NVMe SSD • 13" 1920x1080p 120 Hz IPS touchscreen • dual Thunderbolt 3

Link to post
Share on other sites

Are you sure that autoplay and autorun are enabled?
Enabling autorun/autoplay is bad idea security-wise.

You could force it to be enabled via group policy.
https://www.techrepublic.com/article/how-to-disable-autoplay-and-autorun-in-windows-10/

If you have time, prefer to detect the device dynamically with C# using InteropServices.
https://www.codeguru.com/columns/dotnet/detecting-usb-devices-using-c.html
And you can execute the batch script or even customize it yourself.

Link to post
Share on other sites
Posted · Original PosterOP · Best Answer
7 hours ago, nerdv2 said:

Are you sure that autoplay and autorun are enabled?
Enabling autorun/autoplay is bad idea security-wise.

You could force it to be enabled via group policy.
https://www.techrepublic.com/article/how-to-disable-autoplay-and-autorun-in-windows-10/

If you have time, prefer to detect the device dynamically with C# using InteropServices.
https://www.codeguru.com/columns/dotnet/detecting-usb-devices-using-c.html
And you can execute the batch script or even customize it yourself.

It probably could be done if I knew any programming at all.

 

I found a solution though: I looked up the event ID and source when the external SSD gets plugged in, then I used that as a trigger in Event planner to start the copy "script" stored on the external SSD.

 

However then I was running into an issue where if I plug in another external drive, it starts the copy if the external SSD is still connected. I solved that by making a more detailed filter for the trigger event as shown:

<QueryList>
  <Query Id="0" Path="Microsoft-Windows-Ntfs/Operational">
    <Select Path="System">*[System[Provider[@Name='Microsoft-Windows-Ntfs'] and (Level=4 or Level=0) and (EventID=98) and TimeCreated[timediff(@SystemTime) <= 10000]]]
    
    and
    
    *[EventData[Data[@Name='DriveName'] and (Data='W:')]]</Select>
  </Query>
</QueryList>

I found out how to do that here.

 

This way the event "Import laptop backup" only triggers when the external SSD is inserted, and it ignores any other (NTFS) external drives.


Quote and/or tag people using @ otherwise they don't get notified of your response!

 

The HUMBLE Computer:

AMD Ryzen 7 3700X • Noctua NH-U12A • ASUS STRIX X570-F • Corsair Vengeance LPX 32GB (2x16GB) DDR4 3200MHz CL16 • GIGABYTE Nvidia GTX1080 G1 • FRACTAL DESIGN Define C w/ blue Meshify C front • Corsair RM750x (2018) • OS: Kingston KC2000 1TB GAMES: Intel 660p 1TB DATA: Seagate Desktop 2TB • Acer Predator X34P 34" 3440x1440p 120 Hz IPS curved Ultrawide • Corsair STRAFE RGB Cherry MX Brown • Logitech G502 HERO / Logitech MX Master 3

 

Notebook:  HP Spectre x360 13" late 2018

Core i7 8550U • 16GB DDR3 RAM • 512GB NVMe SSD • 13" 1920x1080p 120 Hz IPS touchscreen • dual Thunderbolt 3

Link to post
Share on other sites

That is a clever hack, now I learn something new.

And hey, I consider batch file and xml scripting is programming.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×