Sunday, October 19, 2008

Reactivating Dynamic Drives for Windows XP Professional

Requires: Windows XP Professional and optionally Ruby, AutoIt

Here's a quick thing that I learned and set up. First, the problem. I frequently use a usb external hard drive at home. As a dynamic disk, everytime I plugged the hard drive in I had to right click my computer, select manage, select disk management, select my external hard drive, and reactivate the disk. Or (after I removed the "My Computer" icon from my desktop) control panel->administrative tools->computer management->disk management->external drive->reactivate disk. It's not too much of a hassle, but it is stupidly annoying to have to go through that sequence often. If you have multiple disks that you want to manually individually activate, always have certain dynamic drives plugged in and want them activated at startup, or (like me) you just don't want to touch the mouse if there's another way, then you'd want a way to automate this process. So I found a way to avoid all the mindless clicking.

It's not really anything new. It's just making use of the diskpart command line utility. Here's documentation on diskpart. I wrote a small ruby script to run the diskpart for me. You can use a static batch script and text file to do this as well. In my actual implementation, I have a different ruby script that makes sure I'm activating the "right" disk. But this sample solution will always activate disk 1:
activateDynamicDisk.rb
view plaincopy to clipboardprint?
  1. require 'win32ole'  
  2. f = File.new"online.txt""w" )  
  3. f.print( "select disk 1\n" )  
  4. f.print( "online\n" )  
  5. f.close  
  6. au3 = WIN32OLE.new("AutoItX3.Control")  
  7. au3.Run( "diskpart /s c:\online.txt" )  
  8. File.delete( "online.txt" )  
Really easy, eh? You can easily set it up to run every time windows boots up. I should also mention dynamic drives only work with Windows XP Pro, so my external drive is unusable with a home edition. Now, the next trick is figuring out how to run this script whenever I plug the device in. I wonder how that's done.

No comments: