//打开光驱
mciSendString('Set cdaudiodo
or open wait', nil, 0, handle);
//关闭光驱
mciSendString('Set cdaudiodo
or closed wait', nil, 0, handle)
设置光盘的自动运行特征:
procedure TForm1.SetCDAutoRun(AAutoRun:Boolean);
const
do
AutoRun : array[Boolean] of Integer = (0,1);
var
Reg : TRegistry;
begin
try
{ create our registry object }
Reg := TRegistry.Create;
{ set our registry root key }
Reg.RootKey := HKEY_LOCAL_MACHINE;
{ verify that our CDROM class key exists }
if Reg.KeyExists('System/CurrentControlSet/Services/Class/CDROM') then
{ try to open our CDROM class key }
if Reg.OpenKey('System/CurrentControlSet/Services/Class/CDROM',FALSE) then
{ add AutoRun to our CDROM class key }
Reg.WriteBinaryData('AutoRun',DoAutoRun[AAutoRun],1);
finally
{ free our registry object }
Reg.Free;
end;
{ showmessage that the changes will happen on reboot }
ShowMessage('Your settings will take effect on the next reboot of Windows.');
end;
拦截消息WM_DEVICECHANGE即可!
//响应该消息
procedure Tform1.WMDEVICECHANGE(var msgx :Tmessage);
const
DBT_DEVICEARRIVAL=$8000;
DBT_DEVICEREMOVECOMPLETE=$8004;
begin
inherited;
case msgx.WParam of
DBT_DEVICEARRIVAL:Caption :='有了!';
DBT_DEVICEREMOVECOMPLETE:Caption :='取走了';
end;
end;
这些资料你瞧瞧有用不?