|
Вопрос # 1 212/ вопрос открыт / |
|
Здравствуйте, уважаемые эксперты!
Хотелось бы узнать каким образом можно узнать имя производителя, модель и вообще как можно больше информации о CD-приводах системы.
Заранее спасибо
 |
Вопрос задал: Илья (Hott Dogg) (статус: Посетитель)
Вопрос отправлен: 19 декабря 2007, 01:17
Состояние вопроса: открыт, ответов: 1.
|
Ответ #1. Отвечает эксперт: Feniks
Здравствуйте, Илья (Hott Dogg)!
Данная тема уже подымалась. Вы можете поискать вопросы/ответы на портале. А информацию можно разную вытягивать: от типа диска, до производителя привода. Т.е. можно и по самим дискам, и по приводам. Вот несколько примеров в Приложении:
1. Блокировка/Разблокировка CD-ROM.
2. Как узнать букву CD-ROM.
3. Как открыть CD-ROM, если их несколько в системе.
4. Как узнать производителя CD/DVD.
5. Изменение скорости привода CD-ROM.
6. Обработать момент вставки и вытаскивания CD.
Ну и хватит... :-)
Приложение: Переключить в обычный режим-
- const
-
-
- IOCTL_STORAGE_MEDIA_REMOVAL = $02D4804;
-
- type
- PREVENT_MEDIA_REMOVAL=record
- PreventMediaRemoval:BOOL;
- end;
-
-
-
- function LockCD(cdLetter:char; fLock:boolean):boolean;
- var
- hDevice : THandle;
- dwBytesReturned : DWORD;
- pmr : PREVENT_MEDIA_REMOVAL;
- begin
- result:=false;
- hDevice := CreateFile(pchar('\.'+cdLetter+':'),GENERIC_READ,
- FILE_SHARE_READ or FILE_SHARE_WRITE,
- nil,OPEN_EXISTING, 0,0);
- if (hDevice=DWORD(-1)) then exit;
-
- try
- pmr.PreventMediaRemoval:=fLock;
- if (not DeviceIoControl(hDevice, IOCTL_STORAGE_MEDIA_REMOVAL, @pmr,
- sizeof(pmr),nil, 0,
- dwBytesReturned, nil)) then exit else result:=true;
- finally
- CloseHandle (hDevice);
- end;
- end;
-
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if not LockCD('E',true) then
- MessageBox(Handle,'Can not lock CD','Error',MB_ICONERROR)
- else
- MessageBox(Handle,'CD is locked','Info',MB_ICONINFORMATION);
- end;
-
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- if not LockCD('E',false) then
- MessageBox(Handle,'Can not unlock CD','Error',MB_ICONERROR)
- else
- MessageBox(Handle,'CD is unlocked','Info',MB_ICONINFORMATION)
- end;
-
-
-
- ===============================================================
-
- function GetFirstCDROMDrive: char;
- var
- drivemap, mask: DWORD;
- i: integer;
- root: string;
- begin
- Result := #0;
- root := 'A:';
- drivemap := GetLogicalDrives;
- mask := 1;
- for i := 1 to 32 do
- begin
- if (mask and drivemap) <> 0 then
- if GetDriveType(PChar(root)) = DRIVE_CDROM then
- begin
- Result := root[1];
- Break;
- end;
- mask := mask shl 1;
- Inc(root[1]);
- end;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- ShowMessage(GetFirstCDROMDrive);
- end;
-
-
- ===============================================================
-
- // DriveTools 1.0 *
- // (c) 1999 Jan Peter Stotz *
- // If you find bugs, has ideas for missing featurs, feel free to contact me *
- // jpstotz@gmx.de *
- // Date last modified: May 22, 1999 *
-
- unit DriveTools;
-
- interface
-
- uses
-
- Windows, SysUtils, MMSystem;
-
- function CloseCD(Drive: Char): Boolean;
- function OpenCD(Drive: Char): Boolean;
-
- implementation
-
- function OpenCD(Drive: Char): Boolean;
- var
-
- Res: MciError;
- OpenParm: TMCI_Open_Parms;
- Flags: DWord;
- S: string;
- DeviceID: Word;
- begin
-
- Result := false;
- S := Drive + ':';
- Flags := mci_Open_Type or mci_Open_Element;
- with OpenParm do
- begin
- dwCallback := 0;
- lpstrDeviceType := 'CDAudio';
- lpstrElementName := PChar(S);
- end;
- Res := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));
- if Res <> 0 then
- exit;
- DeviceID := OpenParm.wDeviceID;
- try
- Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
- if Res = 0 then
- exit;
- Result := True;
- finally
- mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));
- end;
- end;
-
- function CloseCD(Drive: Char): Boolean;
- var
-
- Res: MciError;
- OpenParm: TMCI_Open_Parms;
- Flags: DWord;
- S: string;
- DeviceID: Word;
- begin
-
- Result := false;
- S := Drive + ':';
- Flags := mci_Open_Type or mci_Open_Element;
- with OpenParm do
- begin
- dwCallback := 0;
- lpstrDeviceType := 'CDAudio';
- lpstrElementName := PChar(S);
- end;
- Res := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));
- if Res <> 0 then
- exit;
- DeviceID := OpenParm.wDeviceID;
- try
- Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
- if Res = 0 then
- exit;
- Result := True;
- finally
- mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));
- end;
- end;
-
- end.
-
-
- ===============================================================
-
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, WbemScripting_TLB, OleServer, ActiveX, StdCtrls, ExtCtrls,
- ComCtrls;
- type
- TForm1 = class(TForm)
- ListBox1: TListBox;
- SWbemLocator1: TSWbemLocator;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
-
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- var
- Service: ISWbemServices;
- ObjectSet: ISWbemObjectSet;
- SObject: ISWbemObject;
- PropSet: ISWbemPropertySet;
- SProp: ISWbemProperty;
- PropEnum, Enum: IEnumVariant;
- TempObj: OleVariant;
- Value: Cardinal;
- dr:string;
- begin
- ListBox1.Clear;
- Service:= SWbemLocator1.ConnectServer('.', 'rootCIMV2', '', '', '','', 0, nil);
- SObject:= Service.Get('Win32_CDROMDrive', wbemFlagUseAmendedQualifiers, nil);
- ObjectSet:= SObject.Instances_(0, nil);
- Enum:= (ObjectSet._NewEnum) as IEnumVariant;
- dr:='';
- while (Enum.Next(1, TempObj, Value) = S_OK) do
- begin
- SObject:= IUnknown(TempObj) as SWBemObject;
- PropSet:= SObject.Properties_;
- PropEnum:= (PropSet._NewEnum) as IEnumVariant;
- while PropEnum.Next(1, TempObj, Value) = S_OK do
- begin
- SProp:= IUnknown(TempObj) as SWBemProperty;
- if SProp.Name='Drive' then dr:=SProp.Get_Value;
- if SProp.Name='Name' then ListBox1.AddItem(dr+' '+SProp.Get_Value, nil);
- end;
- end;
- end;
- end.
-
-
-
- ===============================================================
-
-
- function SetCDSpeed(Host,Target:byte;Speed:integer):BOOL;
-
-
- var
- dwASPIStatus: DWORD;
- hEvent: THandle;
- srbExec: SRB_ExecSCSICmd;
- begin
- if Speed<176 then result:=false
- else
- begin
- hEvent:=CreateEvent(nil, true, false, nil);
- Fillchar(srbExec,sizeof(SRB_ExecSCSICmd),0);
- srbExec.SRB_Cmd:= SC_EXEC_SCSI_CMD;
- srbExec.SRB_Flags:= SRB_DIR_OUT or SRB_EVENT_NOTIFY;
- srbExec.SRB_Target:= Target;
- srbExec.SRB_HaId:= Host;
- srbExec.SRB_Lun:= 0;
- srbExec.SRB_SenseLen:= SENSE_LEN;
- srbExec.SRB_CDBLen:= 12;
- srbExec.SRB_PostProc:=Pointer(hEvent);
-
- srbExec.CDBByte[2]:= Speed shr 8;
- srbExec.CDBByte[3]:= Speed;
- srbExec.CDBByte[4]:= $FF;
- srbExec.CDBByte[5]:= $FF;
- ResetEvent(hEvent);
- dwASPIStatus:= SendASPI32Command(@srbExec);
- if dwASPIStatus=SS_PENDING
- then
- begin
- WaitForSingleObject(hEvent,INFINITE);
- end;
- if srbExec.SRB_Status<>SS_COMP
- then
- begin
- MessageBox(0,'Error processing the SRB.','Error',MB_OK);
- result:=false;
- end
- else
- result:=true;
- end;
- end;
-
-
-
-
-
- ===============================================================
-
- {
- Some applications need to know when the user inserts or
- removes a compact disc or DVD from a CD-ROM drive without
- polling for media changes. Windows provide a way to notify these
- applications through the WM_DEVICECHANGE message.
- }
-
- type
- TForm1 = class(TForm)
- private
- procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
- public
-
- end;
-
- {...}
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.WMDeviceChange(var Msg: TMessage);
- const
- DBT_DEVICEARRIVAL = $8000; // system detected a new device
- DBT_DEVICEREMOVECOMPLETE = $8004; // device is gone
- var
- myMsg: string;
- begin
- inherited;
- case Msg.wParam of
- DBT_DEVICEARRIVAL: myMsg := 'CD inserted!';
- DBT_DEVICEREMOVECOMPLETE: myMsg := 'CD removed!';
- end;
- ShowMessage(myMsg);
- end;
-
- {*********************************************}
-
- // Advanced Code:
- // When the device is of type volume, then we can get some device specific
- // information, namely specific information about a logical volume.
- // by Juergen Kantz
-
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- label1: TLabel;
- private
- procedure WMDeviceChange(var Msg: TMessage); message WM_DeviceChange;
- { Private declarations }
- public
- { Public declarations }
- end;
-
- const
- DBT_DeviceArrival = $8000;
- DBT_DeviceRemoveComplete = $8004;
- DBTF_Media = $0001;
- DBT_DevTyp_Volume = $0002;
-
- type
- PDevBroadcastHdr = ^TDevBroadcastHdr;
- TDevBroadcastHdr = packed record
- dbcd_size: DWORD;
- dbcd_devicetype: DWORD;
- dbcd_reserved: DWORD;
- end;
-
- type
- PDevBroadcastVolume = ^TDevBroadcastVolume;
- TDevBroadcastVolume = packed record
- dbcv_size: DWORD;
- dbcv_devicetype: DWORD;
- dbcv_reserved: DWORD;
- dbcv_unitmask: DWORD;
- dbcv_flags: Word;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.dfm}
-
- function GetDrive(pDBVol: PDevBroadcastVolume): string;
- var
- i: Byte;
- Maske: DWORD;
- begin
- if (pDBVol^.dbcv_flags and DBTF_Media) = DBTF_Media then
- begin
- Maske := pDBVol^.dbcv_unitmask;
- for i := 0 to 25 do
- begin
- if (Maske and 1) = 1 then
- Result := Char(i + Ord('A')) + ':';
- Maske := Maske shr 1;
- end;
- end;
- end;
-
- procedure TForm1.WMDeviceChange(var Msg: TMessage);
- var
- Drive: string;
- begin
- case Msg.wParam of
- DBT_DeviceArrival:
- if PDevBroadcastHdr(Msg.lParam)^.dbcd_devicetype = DBT_DevTyp_Volume then
- begin
- Drive := GetDrive(PDevBroadcastVolume(Msg.lParam));
- label1.Caption := 'CD inserted in Drive ' + Drive;
- end;
- DBT_DeviceRemoveComplete:
- if PDevBroadcastHdr(Msg.lParam)^.dbcd_devicetype = DBT_DevTyp_Volume then
- begin
- Drive := GetDrive(PDevBroadcastVolume(Msg.lParam));
- label1.Caption := 'CD removed from Drive ' + Drive;
- end;
- end;
- end;
-
- end.
 |
Ответ отправил: Feniks (статус: Бакалавр)
Время отправки: 19 декабря 2007, 14:33
|
Мини-форум вопроса
Мини-форум пуст.
Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.
|