0

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.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Dan08
1

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.

Votes + Comments
nice Windows hack
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.