No announcement yet.

Script to eject and share USB drive

  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to eject and share USB drive


    I have a client running SBS 2003 standard with windows XP Pro workstations with usb drive connected to the server for backup job. Each week, the user would exchange a Seagate usb drive from the server and when she disconnect the drive and connect the other same make, model and even color drive to the server, it doesn't seem to be sharing even though everything is setup the same on both drive. The temporary solution is to re-share the folder on the drive in order for the backup job to go through properly otherwise it would fail. 1 of the option I can think of is to create a script where the user just click to unshare and eject the drive then replace the drive and then click another script to re-share the drive. But I am not a script guru so if anyone can supply 2 good simple script or a program that can create .vbs or batch file, that would be great.


  • #2
    Re: Script to eject and share USB drive

    If I understand it correctly you like to share a folder or subfolder that you had created on all of the usb-drives you use with the backup.
    Why can't you just share the usb-drive and specify a path to the folder in the backup job?

    Be aware though that the cached drive letters on a computer can easily be taken over by other usb-drives!
    What you can do to avoid this is mounting the usb drives to an emtpy folder instead of a drive letter.
    To accomplish this:
    * First of all remove the assiged drive letter. Use Disk management to remove that of each of the usb-drives that you plan to use for backup media.

    * create a new folder (e.g. c:\backup)
    In the new folder create a subfolder (with a name like media or usb or.. ), share the subfolder.
    * Set the ntfs permission on the new folders and full permissions on the new share.

    Now you have several options:
    - map the local share persistently to a drive letter, that you can use for the backup job
    - use the local folder path with the backup job
    - use the unc path for the backup job

    Unfortunately, there still is the chance the mounting configuration of a usb-drive spontaneously changed, so you always have to manually check the assigned path before running the backup job anyway. But I think it is far more reliable than using a drive letter.

    I'm not saying that it is not possible to write a vbs script that you can launch BEFORE plugging-in an other backup drive and take care of things needed to be done for the drive to be able to use it with the backup job.

    The script captures the USB-change event - then read the label (the name you gave to all the backup drives) of the usb-drive.
    If that name matches a coded string it could force a certain drive letter or
    mount a local folder path to the drive. I guess what the script could do next, is trying to share an existing folder that suppost to be on that usb-drive, configure the share permissions and finally map that share to a certain drive letter.

    (Such a script will end running only when all actions are accomplished, or when you have programmed a time-out value for the events tracing).

    However, the problem is that such a script can getting pretty complexed and creating it can be very pesky and needed to be tested thoroughly before finally going to use it in the real world.

    Last edited by Rems; 11th July 2009, 13:29.

    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts