vbscript - Remove drive letters via batch or vbs scripting -


i searching little batch or vbs script following:

  • find drives in list of valid drive letters, e.g. ['c','d','e','f'], have specific drive name, e.g. 'backupdrive'
  • remove drive letters of found drives no more displayed in windows explorer

any suggestion appreciated.

you can using command line tool "diskpart". stated in official technet documentation if know volume name can remove with:

select volume <volume number> remove letter=<letter> 

you can automate either using script file (as documented here) exact commands, or calling exe objshell.exec on shell object in vbscript , manipulating stdin , stdout accordingly. example can found here. in case better approach because "list volume" there , parse result description , label , act accordingly. afaik sadly way volume number, because not present in wmi or somewhere easier queryable.

please keep in mind diskpart powerful tool, can wipe whole partitions, use caution.

also note:

you cannot remove drive letters on system, boot, or paging volumes. in addition, cannot remove drive letter oem partition, gpt partition unrecognized guid, or of special, non-data, gpt partitions such efi system partition.


Comments