- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Querying the Audio Cd Autorun feature of Win32

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;



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile