如何使用 WMI 和 Python 弹出 CD? [英] How to eject CD using WMI and Python?

查看:18
本文介绍了如何使用 WMI 和 Python 弹出 CD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Windows 的 WMI 库,如何弹出安装在特定 CD/DVD 驱动器中的 CD rom?

Using Windows' WMI library, how can I eject CD rom mounted in a specific CD/DVD drive?

因为我在 Python 上使用 wmi.py 库,所以我要求从 WMI 文档或示例中获取源代码.

I am asking for sources from WMI docs or examples since I am using wmi.py library on Python.

如果解决方案能满足比 Windows 2000 更新的 Windows 计算机并且有多个 CD-ROM,那就太好了.(即我有 D: F: 驱动器,并且都是 CD-ROM 驱动器.我可能想特别在 F: 中弹出 cd.)

It would be great if solution satisfies Windows computer newer than Windows 2000 and having multi CD-ROMs. (i.e. I have D: F: drives and both are CD-ROM drives. I might want to eject cd in F: specifically.)

在网上搜索但找不到任何相关内容.最后一个解决方案必须是拥有 3rd 方二进制文件并从 shell 执行.

Searched on the net but could not find anything relevant. The last solution must be having 3rd party binaries and executing from the shell.

推荐答案

您可以使用 ctypes.

import ctypes

ctypes.windll.WINMM.mciSendStringW(u"set cdaudio door open", None, 0, None)

更新:

如果您有多个驱动器,您可以使用 open 命令在调用上面的函数之前初始化一个特定的设备.例如(未测试).

If you have more that one drive, you can use to open command to initialize a specific device before calling the function above. For example (not tested).

ctypes.windll.WINMM.mciSendStringW(u"open D: type cdaudio alias d_drive", None, 0, None)
ctypes.windll.WINMM.mciSendStringW(u"set d_drive door open", None, 0, None)

另请参阅文档 关于如何检查返回值

Also, see the documentation on how to check return values

这篇关于如何使用 WMI 和 Python 弹出 CD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆