USB Auto Update GuideGuest_Jim_* - May 2, 2013
» Discuss this article (4)
I, like many others, am somewhat lazy. If I can find a way to simplify my life by automating some process, I will do it even if it takes an amount of effort to begin. Well, I guess one could say that because I have put in the effort you now do not have to, or at least not as much effort.
Before I joined the staff here at OCC, I asked a question on the forums about how to use the Windows Task Scheduler to trigger a batch file upon connecting a USB drive. That batch file would contain instructions on how to update files on the USB drive, so I would not need to manually copy files myself. Well, since I developed that first system, the scripts have evolved into one of the more convoluted things I have ever created... but it works! Also, every one of those convolutions is actually needed and add to the system's overall strength, but they do get complicated. Do not do anything in this guide unless you are an advanced computer user. Honestly, I cannot imagine how anything I explicitly tell you to do could mess up your computer, but you should still be careful.
This guide is going to have you work with batch files, possibly the Event Viewer, definitely the Task Scheduler, and maybe Environment Variables. The latter depends on your computer situation. Also, all of this is being done on a Windows 7 machine, so if you are running a different version of Windows, the location of things may be different.
Batch files are scripts that can contain a series (or batch) of instructions which can be executed within the Command Prompt as well as some only useful from within a script, such as GOTO and labels, both of which we will be using. They are actually very useful files and are worth understanding.
The Event Viewer is exactly what its name says. When just about anything happens on your computer, the event is logged by the system and this is where you can view the logs. While viewing these logs it is possible to assign a task to them. The task begins whenever the selected event occurs.
Again, the name gives this one away. This is the system you can use to schedule a task to occur, such as running a program, sending an email, and displaying a message. Without a doubt, we will be visiting this later.
Computer variables, like algebraic variables, stand in for other values. When used within a batch file, variables usually stay there and are not recorded by the system. Environment Variables however are accessible to everything on the computer, and many programs use and create them. You may not need them to get your USB Update system to work, but they are required for me.
Since I've mentioned my situation and setup a few times, and will continue to mention it later on, I think I should explain what makes my setup special, and why it requires the USB Update system to be so convoluted. I have two computers, a laptop and a desktop, with user folders on different drives. The laptop keeps my user folder on the C drive while my desktop keeps it on the E drive. The different drive letters means that the paths to any file are also different. Further, I have and use multiple USB drives of different sizes and purposes. This is why I must use Environment Variables and some other tricks, which will be described later; so no matter the computer or the drive, the files can be appropriately updated.
With that explained, let's get to it!