Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Created April 14, 2015 20:15
Show Gist options
  • Select an option

  • Save SteveGilham/960c0ec46c88f22d02fc to your computer and use it in GitHub Desktop.

Select an option

Save SteveGilham/960c0ec46c88f22d02fc to your computer and use it in GitHub Desktop.
import clr
clr.AddReference("System.Management")
import System
from System.Management import *
logicalDrives = None
def getLogicalDrives():
global logicalDrives
if None == logicalDrives:
DiskSearch = ManagementObjectSearcher(SelectQuery("Select * from Win32_LogicalDisk"))
try:
moDiskCollection = DiskSearch.Get()
logicalDrives = []
try:
for mo in moDiskCollection:
logicalDrives.append(mo["Name"])
mo.Dispose()
finally:
moDiskCollection.Dispose()
finally:
DiskSearch.Dispose()
return logicalDrives
if __name__ == "__main__":
print getLogicalDrives()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment