如何控制光驱,(小雨哥解决问题,300分归他了) (300分)

  • 主题发起人 主题发起人 zlj555
  • 开始时间 开始时间
dbt_DeviceQueryRemove
不行,插拔优盘可以检测到,但光驱不行(没插盘)
 
I found a idea to stop CD ejection .
This is based on locking the volume for exclusive use.

BOOL PreventDiskEject(LPCSTR szDriveLetter, BOOL fLock=TRUE )
{
char szDevice[10];
wsprintf( szDevice,"//./%c:", szDriveLetter[0] );

HANDLE hDevice = CreateFile(
szDevice, // // drive to open... format is "/.X:"
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, NULL
);

DWORD nJunk;
PREVENT_MEDIA_REMOVAL rPMR;
rPMR.PreventMediaRemoval= fLock;
// TRUE or FALSE

BOOL fResult= DeviceIoControl(
hDevice, IOCTL_STORAGE_MEDIA_REMOVAL,
&rPMR, sizeof(rPMR), NULL, 0, &nJunk, NULL
);


CloseHandle( hDevice );
return ( fResult );
}
From:Krishnaa [02-24-2003 11:07 AM]
krishna_pawar@rediffmail.com
 
TO:zlj555 &
zjan521
上面的这段代码转为 Delphi 的代码,我已经贴在:
http://www.delphibbs.com/delphibbs/DispQ.asp?LID=1666855
 
好的,谢谢小雨哥了,我去看看。:)
 
设成共享的,给自己也上个密码就是。
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
后退
顶部