Главная страница | назад





Article #16169: Querying the Audio Cd Autorun feature of Win32

 Question and Answer Database
FAQ1169D.txt Querying the Audio Cd Autorun feature of Win32
Category :Miscellaneous
Platform :All
Product :All 32 bit
Question:
How can I query the Audio Cd Autorun feature of Win32, and how can
I set this value?
Answer:
This setting is stored under the two following Windows registry
keys:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AudioCD\Shell
HKEY_CLASSES_ROOT\AudioCD\Shell
The value will be the string "play" if the Autorun feature is
enabled.
The following example demonstrates both reading and writing these key
values.
Example:
function IsAudioCdAutoRunOn : bool;
var
reg: TRegistry;
Classes : string;
ClassesRoot : string;
i : integer;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey('SOFTWARE\Classes\AudioCD\Shell',
false);
Classes := reg.ReadString('');
reg.CloseKey;
reg.RootKey := HKEY_CLASSES_ROOT;
reg.OpenKey('AudioCD\Shell',
false);
ClassesRoot := reg.ReadString('');
reg.CloseKey;
reg.free;
for i := 1 to length(Classes) do
Classes[i] := UpCase(Classes[i]);
for i := 1 to length(ClassesRoot) do
ClassesRoot[i] := UpCase(ClassesRoot[i]);
result := ((Classes = 'PLAY') and
(ClassesRoot = 'PLAY'));
end;
procedure SetAudioCdAutoRun(bOn : bool);
var
reg: TRegistry;
Classes : string;
ClassesRoot : string;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey('SOFTWARE\Classes\AudioCD\Shell',
false);
if bOn then
reg.WriteString('', 'play') else
reg.WriteString('', '');
reg.CloseKey;
reg.RootKey := HKEY_CLASSES_ROOT;
reg.OpenKey('AudioCD\Shell',
false);
if bOn then
reg.WriteString('', 'play') else
reg.WriteString('', '');
reg.CloseKey;
reg.free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsAudioCdAutoRunOn then
ShowMessage('Autorun Audio Cd is On') else
ShowMessage('Autorun Audio Cd is Off');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SetAudioCdAutoRun(true);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SetAudioCdAutoRun(false);
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99