Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there I am unsure how to go about enumerating or walking through all the hard drives on my computer.

I have 2 internal hard drives and a few external I am able to see all the hard drives in my combobox but I would like to change my approach to how my program works.


I am looking for some advice as to how to detect all connected hard drives and then walk though them one after the other until all hard drives have been searched from start to finish.


Is it possible to return all the hard drives to a string or strings? and then if there is more than one to goto the next?....

thank you in advance
Posted

1 solution

The disks connected to a system have multiple aspects from OS point of view. First of all there is the physical device, but there are also partitions, file systems and so on.
Here is a really exhaustive list of disk related tasks you can manage with WMI: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394592(v=vs.85).aspx[^]. The samples are in vbs, but they can be easily transcribed to vb.net. Here you have some good examples about querying wmi in vb.net: http://msdn.microsoft.com/en-us/library/ms186146(v=vs.100).aspx?cs-lang=vb[^].
 
Share this answer
 
v2
Comments
Dale 2012 30-Dec-12 3:15am    
ok thank you for your response how would this work, lets say i have no idea what the drive letter is or how many are connected?.... can I still use this method to find all hard drives \ removable drives and search through them one by one until the last one has finished?...
Zoltán Zörgő 30-Dec-12 3:20am    
Yes. WMI is a low level infrastructure to access system stuff. Copy-paste the vbs samples and run them to see what they are capable of. And this is a really useful tool to expore wmi data on local or remote system: http://www.ks-soft.net/hostmon.eng/wmi/index.htm
Dale 2012 30-Dec-12 3:23am    
As an example, the following query selects all the drives on a computer (drive C, D, and so on) that have less than 2 MB of free space:


SELECT * FROM Win32_LogicalDisk WHERE FreeSpace < 2000000

this is pretty much all i need to perform my recursive drive operations on all drives?....
Zoltán Zörgő 30-Dec-12 3:29am    
The recursive part in your job, but yes.
Dale 2012 30-Dec-12 3:31am    
Ok I will try this thank you very much for your insight I may post back in a few mins and accept this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900