Hi everyone, I'm doing some experiences with python in Windows Vista and I was wondering to know how to eject the tray of CDs.
Thanks, Dan.
Well, I'm not Dan, but here's a little hack adapted from http://www.dotnetspider.com/resources/15834-eject-close-cd-tray.aspx for Python. It's only two lines of code!
To open:
import ctypes
ctypes.windll.winmm.mciSendStringW("set cdaudio door open", None, 0, None)
To close:
import ctypes
ctypes.windll.winmm.mciSendStringW("set cdaudio door closed", None, 0, None)
Note, if you're using python 2.x, either change mciSendStringW to mciSendStringA, or change the first argument to a unicode string (recommended) by prefixing it with a lowercase u.
Thanks Scru, it works perfectly.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.