Jump to content

How To Make A Usb Drive Copy Files Automatically?


DivineTech
 Share

Recommended Posts

Hello everyone, I am new to Hak5 only been watching for about 2 years now. I was wondering is someone could point me in the right direction. I am a Systems Admin for a pallet company. We have a server that is hosting quickbook .qbw files and wondered if it was possible for me to plug in a USB thumb drive and have it copy the assigned files I gave it. I am not a programmer by any means but am willing to learn. I know a little batch scripting but it seems that windows 7 is not [autorun]ing my batches. I just want to plug it in and walk away. I want to do something like this

@echo off

:: variables

SET odrive=%odrive:~0,2%

set backupcmd=xcopy /s /c /d /e /h /i /r /y

echo off

%backupcmd% "%USERPROFILE%\quickbooks" "%drive%\backup\quickbooks"

@echo off

Link to comment
Share on other sites

Thank you abs0lut3z33r0 for that info, after researching the issue I became very aware of this. However I found something that might be useful to others trying to do this.

I was able to go in to the windows powershell and create my own task.

Goto: Start>Accessories>Windows PowerShell> Windows PowerShell ISE (x86).

Copy & Paste:

3. #Requires -version 2.0

4. Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange

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

6. do{

7. $newEvent = Wait-Event -SourceIdentifier volumeChange

8. $eventType = $newEvent.SourceEventArgs.NewEvent.EventType

9. $eventTypeName = switch($eventType)

10. {

11. 1 {"Configuration changed"}

12. 2 {"Device arrival"}

13. 3 {"Device removal"}

14. 4 {"docking"}

15. }

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

17. if ($eventType -eq 2)

18. {

19. $driveLetter = $newEvent.SourceEventArgs.NewEvent.DriveName

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

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

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

23. # Execute process if drive matches specified condition(s)

24. if ($driveLetter -eq 'H:' -and $driveLabel -eq 'Mirror')

25. {

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

27. start-sleep -seconds 3

28. start-process "H:\file.bat"

29. }

30. }

31. Remove-Event -SourceIdentifier volumeChange

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

33. Unregister-Event -SourceIdentifier volumeChange

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 'H:' -and $driveLabel -eq 'Mirror')

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

- start-process "Z:\file.bat"

Path of whatever task you want to do. In my example, I have created a batch file on my USB drive which start backup tasks command lines.

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 "C:\Backup script.ps1"

I can’t take credit for this because I found it on a Google search. But like I always tell my friends, “I don’t have all the answers but I know where to find them”

I am having a few bugs with this scrip so Its not yet working @ 100%. I will keep you updated as I progress.

Link to comment
Share on other sites

I put together a tutorial to show how you can copy files automatically to your thumb drive or external hard drive in windows 7. This comes in handy when you need to backup QuickBooks files on the fly. I am an outside tech for a pallet company that has a server running a raid 5 with windows 7 ultimate edition. All it does mainly is host QuickBooks files. Well on Saturday there was a transformer that exploded and blew out some computers. Luckily the server wasn’t one of them. However this mishap induced fear in to the owner. He wanted to take one of the hard drives home with him every night to insure his data wouldn’t be lost if there were to be another fuck up. This posed a problem since he only has three 1tb hard drives running on a raid 5. This was my solution to his problem. Since he only had 985mb total to his whole business. I could make him a USB thumbs drive that when plugged in it to the server it would auto backup all his files. I chose a thumb drive that had a light indicator on it because the server doesn’t have a monitor hooked up to it. I needed some indication to let me know when it was ok to pull out the drive. No light = not copying. What I like most about this set-up is that every time you plug in the drive it only copies the files that had been modified rather than copying the whole 985mb.

I cannot take credit for this information. With a lot of Google searching I was able to put together the information from different sources in to a step by step tutorial. It would be cool if there was a way to circumvent the windows PowerShell and task scheduler portion of my tutorial. Like I said before I’m not a programmer so I wouldn’t know where to start.

There might be portions of my tutorial that might not be necessary or is not 100% correct. All I did was put down what worked for me. If you have any input or ideas please share. I enjoy learning new things.

How To Make A Usb Drive Copy Files Automatically in Windows 7 :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...