Exemplo de código para ejetar CD DVD
import os, sys
print(sys.platform)
if 'win' in sys.platform:
import win32file
from win32con import *
drive = 'E:' # Colocar a letra da unidade de CD/DVD do seu sistema
h = win32file.CreateFile(r'\\.\\' + drive, GENERIC_READ,FILE_SHARE_READ,None, OPEN_EXISTING, 0, 0)
win32file.DeviceIoControl(h, 0x002d4808, "", 0, None) # Envia um codigo de controle para um dispositivo
win32file.CloseHandle(h)
else:
import fcntl
cd_device = '/dev/cdrom'
if os.path.islink(cd_device):
base_path = os.path.dirname(cd_device)
cd_device = os.readlink(cd_device)
if not cd_device[0] == '/':
cd_device = os.path.join(base_path, cd_device)
cdrom = os.open(cd_device, os.O_RDONLY | os.O_NONBLOCK)
fcntl.ioctl(cdrom, 0x5309, 0)
os.close(cdrom)
print(sys.platform)
if 'win' in sys.platform:
import win32file
from win32con import *
drive = 'E:' # Colocar a letra da unidade de CD/DVD do seu sistema
h = win32file.CreateFile(r'\\.\\' + drive, GENERIC_READ,FILE_SHARE_READ,None, OPEN_EXISTING, 0, 0)
win32file.DeviceIoControl(h, 0x002d4808, "", 0, None) # Envia um codigo de controle para um dispositivo
win32file.CloseHandle(h)
else:
import fcntl
cd_device = '/dev/cdrom'
if os.path.islink(cd_device):
base_path = os.path.dirname(cd_device)
cd_device = os.readlink(cd_device)
if not cd_device[0] == '/':
cd_device = os.path.join(base_path, cd_device)
cdrom = os.open(cd_device, os.O_RDONLY | os.O_NONBLOCK)
fcntl.ioctl(cdrom, 0x5309, 0)
os.close(cdrom)
Comentários
Postar um comentário