Windows ‘No Disk’ Error

November 20th, 2007 13:06

I recently came across a strange bug when I ran an installed version of some software on Windows. The following error dialog was being displayed:

No Disk

I have a network drive mapped on my machine so I unmapped it and then reran the process. No joy, the same error dialog was displayed.

I also have a one MemoryStick and one SD slot on my lappie, so I stuck a card into each one and reran. Everything worked fine. So I now knew it was directly linked to the removable media drives on the machine.

I did a bit of testing then and noted it that was a call to os.access which resulted in the error dialog.

I changed the code to use the win32api.GetFileAttributes call but this too resulted in the same ‘No Disk’ error.

I then tried to write a temp file to the root of the drive and if this failed deduce the drive was read only. This also produced the same ‘No Disk’ error.

I then had a thought, all these drives in windows are just logical drives. So there must be an api to find the physical drives that have been mounted. If I could get the list of physical drives I could probably find the logical drives that reside on them. I found the solution using WMI.

So here’s the snippet of code to find all writeable drives (fixed, removable and optical) on windows:

import win32con
SUPPORTED_DRIVES = [
  win32con.DRIVE_REMOVABLE,
  win32con.DRIVE_FIXED,
  win32con.DRIVE_CDROM
]

import wmi
w = wmi.WMI ()

drives = []
dd2dp = "Win32_DiskDriveToDiskPartition"
ld2p = "Win32_LogicalDiskToPartition"
for disk in w.Win32_DiskDrive():
  for partition in disk.associators(dd2p):
    for logical_disk in partition.associators(ld2p):
      drive = logical_disk.Caption
        if logical_disk.DriveType in SUPPORTED_DRIVES:
          if os.access(drive, os.W_OK):
            drives.append(drive)
          else:
            print "Ignoring read only drive '%s'" % drive
        else:
          print "Ignoring unsupported drive type '%s'" % drive

One Response to “Windows ‘No Disk’ Error”

  1. Glen Beltran Says:

    Thank you so much for posting this! That error was driving me crazy whenever I launched the Avid EDL Manager and Film Scribe I would get that message. I disabled my external drives and MAGIC the error went away.

    My sincerest thanks!

Leave a Reply